简体   繁体   English

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

[英]Update TOC in .docx document using DocumentFormat.OpenXml (C#)

I create new word document using DocumentFormat.OpenXml. 我使用DocumentFormat.OpenXml创建新的Word文档。 I load template document in which located the table of content and the table with picture logo. 我加载的模板文档位于目录和带有图片徽标的表中。 I append other content using c# code for this template. 我为此模板使用c#代码附加了其他内容。 I send this document to user. 我将此文件发送给用户。

When user get this document and open it - the table of contents not update. 当用户获取此文档并打开它时-目录不会更新。 I found the resolve this problem. 我发现解决了这个问题。 I add to my code 我添加到我的代码

  • mainPart.DocumentSettingsPart.Settings.Append(new UpdateFieldsOnOpen() { Val = true }); mainPart.DocumentSettingsPart.Settings.Append(new UpdateFieldsOnOpen(){Val = true});

But when user will get the document and will open it he get the message from MS Word "You wanna update fields?". 但是,当用户获取并打开文档时,他会从MS Word中收到消息“您要更新字段吗?”。

Is there any other way to generate table of contents or update table of contents without any message to user? 有没有其他方法可以生成目录或更新目录,而无需向用户发送任何消息?

I got answer for my question: http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f53a939-f50e-423d-90fa-1f3c58945a6e 我得到了我的问题的答案: 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 下面的博客文章介绍了更新目录的“正确”方法: 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. 除此之外,唯一可用的是嵌入在文档或使用自动化来强制字段更新的插件中的宏。

We have had a long discussion in similar thread regarding generating Table Of Content (TOC) with help of OpneXML SDK 2.0. 我们已经在类似的话题中进行了很长的讨论,有关如何借助OpneXML SDK 2.0生成目录(TOC)。 And there is a detailed solution explaining how it could be achieved. 并且有详细的解决方案说明了如何实现。 Look at this thread for details: How to generate Table Of Contents using OpenXML SDK 2.0? 查看此线程以了解详细信息: 如何使用OpenXML SDK 2.0生成目录?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用DocumentFormat.OpenXml(c#)合并Word文档 - Merging word-documents using DocumentFormat.OpenXml(c#) 使用Documentformat.OpenXML在C#中验证Excel文件 - Validate Excel file in c# using Documentformat.OpenXML 使用DocumentFormat.OpenXml导出带有页脚的DocX文件 - Export DocX file with Footer using DocumentFormat.OpenXml 从 excel 单元格中检索数据,即 C# documentformat.openxml 中的 integer.xslx 文档 - Retrieving data from excel cell that is integer .xslx document in C# documentformat.openxml 如何使用DocumentFormat.OpenXml C#获取excel工作表中的特定列? - How can I get the specific column in excel worksheet using DocumentFormat.OpenXml C#? 使用Microsoft DocumentFormat.OpenXml SDK在C#中读取Excel文件 - Reading excel file in c# using Microsoft DocumentFormat.OpenXml SDK 如何使用 C# 和 DocumentFormat.OpenXml nuget ZEFE90A8E604A7C84A70E8 格式化 Excel 中的数字 - How to format number in Excel by using C# and DocumentFormat.OpenXml nuget package? 如何使用 DocumentFormat.OpenXML 或 ClosedXML C# 从 Excel 获取合并单元格 - How to get a merged cell from Excel using DocumentFormat.OpenXML or ClosedXML C# DocumentFormat.OpenXml修改文档的创建者属性 - DocumentFormat.OpenXml Modify Creator Propery of Document 使用DocumentFormat.OpenXml替换Word中的数据 - Replacing data in word using DocumentFormat.OpenXml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM