Word/OpenXML - 如何创建隐藏书签?
我在 OpenXML API 或 Word/VSTO API 方面都没有找到创建或修改书签可见性的方法。即使在 Word 中手动添加书签,也没有复选框可以使书签隐藏。尽管“书签”对话框中有一个复选框,可让您显示隐藏的书签。那么,隐藏书签是如何在 XML 中表示的?您可以使用 Open XML SDK 创建它们吗?或者它们是微软不再希望我们创造的遗留事物?
I've not had any luck in either the OpenXML API or Word/VSTO API, finding a way to create or modify a bookmark's visibility. Even adding bookmarks manually in Word, there's no box to check to make the bookmark hidden. Although there is a checkbox in the Bookmarks dialog that lets you show hidden bookmarks. So how are hidden bookmarks represented in the XML, and can you create them using the Open XML SDK? Or are they a legacy thing that MS no longer wants us to create?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,这比我想象的要容易......你只需在书签名称前面加上下划线即可。请注意,这只能通过编程来完成,而不能在 Word 中手动添加书签时完成。
Iiiiiiii有趣....
更新:我发现的另一件事 - 在您可以迭代或访问 书签 对象,您必须设置其 ShowHidden 属性设置为 true。
PS-所以,如果您对拼写字典有任何控制权,您可以添加“以编程方式”。除非我拼写错误。 :)
OK so this is easier than I thought...you just precede the bookmark name with an underscore. Note that this can only be done programmatically, not when adding bookmarks manually in Word.
Iiiiiiiiinteresting....
Update: Another thing I found--before you can iterate or access hidden bookmarks in a Bookmarks object, you must set its ShowHidden property to true.
PS - SO, if you have any control over your spelling dictionary, you might add "programmatically". Unless I'm spelling it wrong. :)
我在Word文件中创建了普通书签,然后以编程方式将它们转换为隐藏书签。如上所述,隐藏书签只能以编程方式创建,并且其名称前面带有“_”。迭代书签列表时,请确保将 Bookmarks.ShowHidden 设置为 true,否则隐藏的书签将不会显示在列表中。下面是我用来隐藏所有可见书签的代码。最后我还清除了撤消记录,以确保用户无法撤消我所做的更改。如果您愿意,您可以创建自定义撤消记录删除最后一个操作。
I created normal bookmarks in word file and than converted them to hidden bookmark programmatically. As said above hidden bookmarks can only be created programmatically and their name precede by "_". When ever iterating the bookmarks list make sure
Bookmarks.ShowHidden
is set to true, otherwise hidden bookmarks will not show up in the list. Below is the code that I used to hide all the visible bookmarks. At the very end I also clear undo record to make sure user can not undo the changes I made. You may create the custom undo record delete the last action if you wish.