在 Microsoft Word 文档中存储任意元数据

发布于 2024-07-17 01:16:23 字数 228 浏览 2 评论 0原文

我需要将自定义元数据存储在 Word 文档中。 “文档属性”限制为 255 个字节,但我的数据是 >> 10k

我们正在使用VBA编写一个word扩展来与我们的应用程序交互,并希望将我们的应用程序数据存储在word文档中。 我们的想法是,用户可以只共享 Word 文档,而无需共享我们应用程序的任何其他数据文件。

有谁知道如何在 Office 2003+ 文档中有效存储任意元数据?

I need to store custom meta-data in a Word document. The 'document properties' are limited to 255 bytes but I have data which is >> 10k

We are using VBA to write a word extension to interact with our application and want to have our application data stored in the word document. The idea is that that the user can share just the word document without sharing any other data files of our application.

Has anyone ideas how to store arbitrary meta-data efficently in Office 2003+ documents?

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

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

发布评论

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

评论(2

暮倦 2024-07-24 01:16:23

刚刚在 VBA 编辑器即时窗口中尝试了此操作:

ActiveDocument.Variables.Add "foo", String(10000, ".")

? Len(ActiveDocument.Variables("foo"))
10000

文档变量与文档一起存储。 正如我刚刚发现的那样,它们似乎最多有 65280 个 Unicode 字符(在 Word 2003 中测试;更新:此限制在 Word 2007 和 2010 中是相同的)。

如果您担心数据接近 60k,我建议您将其拆分为多个变量,或者在存储之前对其进行压缩。 这篇文章展示了在 VBA 中执行此操作的一些选项。

Just tried this in the VBA editor immediate window:

ActiveDocument.Variables.Add "foo", String(10000, ".")

? Len(ActiveDocument.Variables("foo"))
10000

Document variables are stored with the document. They seem to go up to 65280 Unicode characters, as I just found out (tested in Word 2003; Update: This limit is the same in Word 2007 and 2010).

If you fear to get near the 60k for your data, I'd recommend either splitting it over several variables, or compressing it before you store it. This post shows some options to do that in VBA.

人海汹涌 2024-07-24 01:16:23

它不完全符合您的要求,因为它不适用于 Word 2003。但是,您可能仍然会对它感兴趣(否则我建议您按照 Tomalak 的建议使用文档变量):

在 Word 2007(及更高版本)中,您可以嵌入任意Word 文档中的 XML 文档为 自定义 XML

MSDN 上的这篇文章描述了一个示例:如何:将自定义 XML 部件添加到使用 VSTO 加载项的文档

It fits not exactly your requirements because it does not work with Word 2003. However, it still might be interesting to you (otherwise I recommend you to use document variables as suggested by Tomalak):

In Word 2007 (and later) you may embed arbitrary XML documents in a Word document as Custom XML.

An example is described ins this article on MSDN: How to: Add Custom XML Parts to Documents by Using VSTO Add-Ins

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