我使用 DocumentFormat.OpenXml 创建新的 word 文档。 我加载了模板文档,其中包含目录和带有图片 Logo 的表格。我使用此模板的 c# 代码附加其他内容。 我将此文档发送给用户。
当用户获取此文档并打开它时 - 目录不会更新。 我找到了解决这个问题的方法。我添加到我的代码中
- mainPart.DocumentSettingsPart.Settings.Append(new UpdateFieldsOnOpen() { Val = true });
但是当用户获取文档并打开它时,他会收到来自 MS Word 的消息“你想更新字段吗?”。
有没有其他方法可以在不向用户发送任何消息的情况下生成目录或更新目录?
最佳答案
我的问题得到了答案: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f53a939-f50e-423d-90fa-1f3c58945a6e
The cause of what you're seeing is a security measure that was introduced a few years ago. Possibly, you can suppress the message by using the Registry entry described in the following KB article. You need to be aware, however, that this could reduce system security.
The following blog article describes the "correct" way to update the TOC: http://support.microsoft.com/kb/330079
Other than that, the only thing available would be a macro embedded in the document or in an addin that uses automation to force the fields to update.
关于c# - 使用 DocumentFormat.OpenXml (C#) 更新 .docx 文档中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8560753/