delphi word书签位置插入字符串【TOLEContainer】 (2011-04-20 00:15:09)
转载: http://hi.baidu.com/xiaoqing2305/blog/item/0f37df1348906dc1f6039ec0.html 以下是三种往 FWord 【TOLEContainer】中嵌入的word文档中的书签位置插入字符串的方法: procedure TDesSeal.AddCommentEx(Bookmark, Comment: string); var bookmarkCount: Integer; bookmarkName: string; i: Integer; begin if FWord<>nil then begin with FWord do begin if State<>osUIActive then DoVerb(ovPrimary); bookmarkCount := OleObject.Application.ActiveDocument.Bookmarks.Count; for i:=1 to bookmarkCount do begin bookmarkName := OleObject.Application.ActiveDocument.Bookmarks.Item(i).Name; if SameText(Bookmark, bookmarkName) then OleObject.Application.ActiveDocument.Bookmarks.Item(i).Range.InsertAfter(Comment); end; end; end; end; procedure TDesSeal.AddComment(Bookmark, Comment: string); var What: olevariant; Which: olevariant; Count: olevariant; Name: olevariant; FSelection: OleVariant; begin if FWord<>nil then begin with FWord do begin if State<> osUIActive then DoVerb(ovPrimary); What := $FFFFFFFF; Name := Bookmark; FSelection := OleObject.Application.Selection; FSelection.GoTo(What,Which,Count,Name); FSelection.TypeText(Comment); end; end; end; procedure TDesSeal.AddCommentW(Bookmark, Comment: string); var bookmarkName: OleVariant; i: Integer; begin if FWord<>nil then begin with FWord do begin if State<>osUIActive then DoVerb(ovPrimary); if OleObject.Application.ActiveDocument.Bookmarks.Exists(Bookmark) then begin bookmarkName:=bookmark; OleObject.Application.ActiveDocument.Bookmarks.Item(bookmarkName).Select; OleObject.Application.ActiveDocument.Bookmarks.Item(bookmarkName).Range.Text:=Comment; end; end; end; end; |
|