c# - 使用 DocumentFormat.OpenXml (C#) 更新 .docx 文档中的目录

标签 c# .net openxml tableofcontents

我使用 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/

相关文章:

c# - 对查询字符串 ABC 顺序进行排序(使用 Unix 风格区分大小写的排序顺序),不带分隔符

c# - 时间跨度减去秒表倒计时

c# - OpenXML 与 MS Excel 中的自定义列宽

c# - 使用 OpenXML 将背景图像添加到 Excel

c# - 重新抛出无参数 catch 和什么都不做的区别?

c# - 无法重命名 Visual Studio 2010 项目

c# - 从二进制字符串中获取具有相同编号的子字符串。 1 和 0 作为单独的组

C#单向链表实现

c# - LINQ 如何在 using 语句中延迟执行

c# - OpenXml 和无法创建互斥量