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);varbookmarkCount: Integer;bookmarkName: string;i: Integer;beginif FWord<>nil thenbeginwith FWord dobeginif State<>osUIActive thenDoVerb(ovPrimary);bookmarkCount := OleObject.Application.ActiveDocument.Bookmarks.Count;for i:=1 to bookmarkCount dobeginbookmarkName := OleObject.Application.ActiveDocument.Bookmarks.Item(i).Name;if SameText(Bookmark, bookmarkName) thenOleObject.Application.ActiveDocument.Bookmarks.Item(i).Range.InsertAfter(Comment);end;end;end;end;procedure TDesSeal.AddComment(Bookmark, Comment: string);varWhat: olevariant;Which: olevariant;Count: olevariant;Name: olevariant;FSelection: OleVariant;beginif FWord<>nil thenbeginwith FWord dobeginif State<> osUIActive thenDoVerb(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);varbookmarkName: OleVariant;i: Integer;beginif FWord<>nil thenbeginwith FWord dobeginif State<>osUIActive thenDoVerb(ovPrimary);if OleObject.Application.ActiveDocument.Bookmarks.Exists(Bookmark) thenbeginbookmarkName:=bookmark;OleObject.Application.ActiveDocument.Bookmarks.Item(bookmarkName).Select;OleObject.Application.ActiveDocument.Bookmarks.Item(bookmarkName).Range.Text:=Comment;end;end;end;end;