DOCX(Open XML WordprocessingDocument)中唯一 ID 的最佳位置

发布于 2024-07-14 23:47:58 字数 655 浏览 5 评论 0原文

我正在寻找一种方法来识别 DOCX 文件(如果它们被移动或重命名)。 原因很明显,我正在使用 Open XML SDK,构建一个超链接检查器。

工作完美,至少它可以添加或更新文档中的超链接。

但问题是,如果我重命名外部文件(source.docx + target.docx 为 targetB.docx),链接就会损坏。 我可以找到损坏的链接(只需检查链接的文件是否位于其给定位置)。

但我想要更多。 我希望能够通过搜索目录(docx)中的所有文档并扫描它们是否是“目标”来恢复丢失的链接。 最简单的方法应该是将 GUID 存储在文档属性中的某个位置,如果文档被重命名或编辑,它不会改变(校验和不适用)。

然后我创建一个单独的链接列表和相应的 ID,如果有任何文档被重命名,我只需更新链接。 我希望这个概念是清楚的。

所以有几个基本问​​题:

  • 是否有存储的“最佳实践” 此“自定义信息”在 Open XML 文档
  • 执行以下操作: 文字处理文档 (DOCX) 已经 创建了一些唯一标识符 by Word
  • 你会在哪里保存映射(超链接目标的 GUID)

我希望问题很清楚,如果不是我会尝试澄清,如果有问题请发表评论..

谢谢, 克里斯

I am looking for a way to indentify DOCX files if they are moved or renamed. Reason is obvious, I am playing with the Open XML SDK, building a hyperlink checker.

Works perfect, at least it can add or update hyperlinks in a document.

Problem is, though, if I rename an external file (source.docx + target.docx to targetB.docx) the link is broken. I can find broken links (by simply checking if the linked file is in its given place).

But I want more. I want to be able to recover this lost links, by searching for all documents in a directory (docx) and scanning if they are the "target". The most simple way should be a GUID stored somewhere in the document properties, which will not change if the document is renamed or edited (checksum is no applicable).

Then I create either a seperate list of links and according IDs, and if any document is renamed, I just update the link. I hope the concept is clear.

So there are a few basic questions:

  • Is there a "best practice" to store
    this "custom information" in an Open
    XML Document
  • Does a
    wordprocessingdocument (DOCX) already
    have some unique identifier created
    by Word
  • Where would you save the mapping (GUID of hyperlink target)

I hope the question is clear, if not I try to clarify, just comment if questions..

Thanks,
Chris

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

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

发布评论

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

评论(3

幸福丶如此 2024-07-21 23:47:58

因为这是五年前的事了,我希望你能找到答案。 如果其他人对此感兴趣,最好的选择是在 ZIP 存档 (\docProps\custom.xml) 中创建一个新的自定义属性,并将元数据存储在其中。 最简单的方法是在 Word UI 中生成一个来查看它们是如何工作的,但是您最终会在 DOCX 存档中得到一个 custom.xml,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
  <property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="test">
    <vt:lpwstr>chris</vt:lpwstr>
  </property>
</Properties>

这些工作如何全部记录在 ECMA 376,记录文件格式的标准。

据我所知,Word 不存储任何 GUID 来唯一标识文件。

As this was five years ago, I'm hoping you found an answer. In case anyone else is interested in this, the best bet would be to create a new custom property in the ZIP archive (\docProps\custom.xml) and store your metadata in that. Easiest way will be to generate one in the Word UI to see how they work, but you'll end up with a custom.xml inside the DOCX archive that looks something like:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
  <property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="test">
    <vt:lpwstr>chris</vt:lpwstr>
  </property>
</Properties>

How these work is all documented in ECMA 376, the standard documenting the file format.

As far as I know, Word does not store any GUIDs to uniquely identify a file.

很酷不放纵 2024-07-21 23:47:58

创建新文档时,MS Word 会生成唯一 ID (GUID) 自 Office 2013 起。 它将其放置在内的文件“\word\settings.xml”中 元素作为“docId”名称。

例如,在 MS Word 2016 中:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:settings xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se">
    <w15:docId w15:val="{982A3D80-A23D-4148-8230-4160F3D87FF5}"/>
</w:settings>

注意,创建文件副本时 MS Word 不会更改它。 因此,如果每个新文件都是创建的而不是从另一个文件复制的,那么这是一种可靠的方法。

MS Word generates unique ID (GUID) when creating a new document since Office 2013. It places it in file '\word\settings.xml' inside <w:settings> element as 'docId' name.

For instance in MS Word 2016:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:settings xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" mc:Ignorable="w14 w15 w16se">
    <w15:docId w15:val="{982A3D80-A23D-4148-8230-4160F3D87FF5}"/>
</w:settings>

Note, that MS Word doesn't change it when a file copy is made. So, if each new file is created rather than copied from another, it's a reliable way.

莫言歌 2024-07-21 23:47:58

Acrobat/PDF 有类似的东西。 查找贝茨编号,它用于通过输入唯一的编号来识别文档。

您通常应该将其放在元数据部分(如果有)中。 或者,将自定义部分添加到 docx 文件中以保留映射(当然,保持在规范的范围内)。 (我对 docx 格式不太熟悉,所以你会明白这一点。)

Acrobat/PDF has something similar. Look up Bates numbering which is used to identify documents by putting in a unqiue number.

You should typically place this in the metadata section, if any. Or, add a custom part to the docx file that keeps the mapping (of course, remaining within the bounds of the spec). (I am not very familiar with the docx format, so you'll have figure this out.)

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