Microsoft Word VSTO Addin - 替换书签而不删除它们

发布于 2024-12-29 10:27:22 字数 531 浏览 0 评论 0原文

我正在为我们正在使用的 Word 模板开发 Word 2010 插件。我的页面中有几个书签,可以使用插件中的各种向导来更改它们的内容。

我现在需要将图像和表格添加到书签 - 这工作正常,但之后立即删除书签。我使用以下代码,传入 bookmark.Range 作为参数。

添加表格:

bookmark.Range.Tables.Add(bookmark.Range, rowCount, columnCount, ref _objectMissing, ref _objectMissing);

添加图像:

InlineShape shape = bookmark.Range.InlineShapes.AddPicture(path, ref _objectMissing, ref _objectMissing, ref _objectMissing);

我需要能够在不删除书签的情况下执行此操作,以便在用户再次运行向导时可以返回并替换图像。任何如何做到这一点的想法将不胜感激!

I am working on a Word 2010 addin for a word template we are using. I have several bookmarks in the page, and their content can be changed using various wizards in the addin.

I need to add images and tables to the bookmarks now - and this works fine, but deletes the bookmark immediately afterwards. I am using the following code, passing in the bookmark.Range as a parameter.

Adding a table:

bookmark.Range.Tables.Add(bookmark.Range, rowCount, columnCount, ref _objectMissing, ref _objectMissing);

Adding an image:

InlineShape shape = bookmark.Range.InlineShapes.AddPicture(path, ref _objectMissing, ref _objectMissing, ref _objectMissing);

I need to be able to do this without deleting the bookmark, so that I can go back and replace the image if the user runs the wizard again. Any ideas how to do this would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰認得朕 2025-01-05 10:27:22

InlineShape 和 Table 对象都有一个 Range 属性,您可以使用该属性来恢复书签,如下所示:

// Keep the name of the bookmark
string bookmarkName = bookmark.Name;
// Insert your image, as before
InlineShape shape = bookmark.Range.InlineShapes.AddPicture(path, ref _objectMissing, ref _objectMissing, ref _objectMissing);
// Restore the bookmark
Object range = shape.Range;
yourDocumentVariable.Bookmarks.Add(bookmarkName, ref range);

Both InlineShape and Table objects have a Range property that you can use to restore the bookmark, like this:

// Keep the name of the bookmark
string bookmarkName = bookmark.Name;
// Insert your image, as before
InlineShape shape = bookmark.Range.InlineShapes.AddPicture(path, ref _objectMissing, ref _objectMissing, ref _objectMissing);
// Restore the bookmark
Object range = shape.Range;
yourDocumentVariable.Bookmarks.Add(bookmarkName, ref range);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文