在Word文档中无形地标记文本

发布于 2024-08-11 10:10:41 字数 806 浏览 1 评论 0原文

我不想构建一个 Word 2007 插件,该插件允许用户:

  • 在 Word 文档中突出显示文本的段落等。
  • 单击工具栏按钮或从右键单击菜单中选择一个选项,将文本“标记”为某种数据类型(将有 4 种不同类型数据中的 3 种)
  • 此外,还可以选择某些文本并取消标记(这将自动扩展选择范围以覆盖整段标记文本)。

标记文档的人是非技术人员,因此我们希望保持简单。

我一直在研究一些不同的方法来实现这一点,包括:

  1. 书签 - 命名书签,即每次突出显示并“标记”类型时,应用程序都会添加一个带有类型名称的书签,后跟一个数字,即 my_custom_type-1、my_custom_type- 2 等
  2. 隐藏文本 - 将隐藏文本粘贴到文档中(其中字体设置为隐藏) - 因此我们基本上可以用一些隐藏文本包围选定的段落,即 {my_custom_type} ... {/my_custom_type},一些其他类型的文本与 {another_custom_type} ... {/another_custom_type} 等
  3. 命名样式 - 为每种数据类型提供样式,并且只需使用 Range.set_Style(...) 方法来设置样式。

到目前为止,我已经尝试过选项 3 - 它似乎可以很好地标记文本,但当我尝试 umark 文本时效果不佳(它不起作用,例如,如果我尝试将类型设置回“正常”)使用 set_Style 方法)。

这些是以编程方式标记 Word 文档中的文本的唯一方法吗(无需在文档中实际显示其他内容) - 任何人都可以推荐一种方法而不是另一种方法,特别是当我们需要解析所有已标记的数据时。

I wan't to build a word 2007 add-in that allows users to:

  • Hilight pargraphs etc. of text in a word document.
  • Click a toolbar button or select an option from a right-click menu to "mark" the text as being some type of data (there will be 3 of 4 different types of data)
  • Also, the ability to select some text and and unmark it (this would automatically expand the selection to cover the full piece of marked up text).

The people marking up the documents will be non-technical, so we want to keep it very simple.

I have been investigating some different ways I could implement this including:

  1. Bookmarks - naming bookmarks i.e. each time a type is hilighted and "marked" the app would add a bookmark with the type name followed by say a number i.e. my_custom_type-1, my_custom_type-2 etc.
  2. Hidden text - sticking hidden text into the document (where font is set to hidden) - so we could basically surround a selected paragraph with some hidden text i.e. {my_custom_type} ... {/my_custom_type}, some other type of text with {another_custom_type} ... {/another_custom_type} etc.
  3. Named styles - having styles for each of the types of data, and just using the Range.set_Style(...) method to set the style.

So far I've tried option 3 - which seems to be working well to mark up text, but not so well when I try to umark text (it doesn't work, if I for example try setting the type back to "normal" using the set_Style method).

Are these the only ways for marking up text in a word document programmatically (without physically displaying additional content in the document) - and can anyone recommend one approach over another, especially when we need to then parse all the data out that's been marked up.

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

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

发布评论

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

评论(1

画中仙 2024-08-18 10:10:41

您可能想尝试使用突出显示(如工具栏上的黄色荧光笔图标)。有多种不同的颜色可供选择 - 当然足以满足您的需求。由于突出显示是除所有其他格式之外的,并且实际上很少是文档“真实”格式的一部分,因此这似乎是一个不错的选择。关闭它非常容易,因为您无需担心会破坏文本的其他格式。您还有一个现成的 UI :-)

You might want to try using highlighting (as in the yellow-highlighter icon on the toolbar). There are several different colours available - certainly enough for your needs. Since highlighting is in addition to all the other formatting, and rarely actually part of the "real" formatting of the document, it seems like a good choice. It'd be really easy to turn off, since you don't need to worry about splatting the other formatting of the text. You also have a ready-made UI :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文