分享

delphi word书签位置插入字符串【TOLEContainer】

 逸随风清 2021-06-01

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;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多