使用DocumentFormat.OpenXml中的.docx文件更新目录(C#) [英] Update TOC in .docx document using DocumentFormat.OpenXml (C#)

查看:1355
本文介绍了使用DocumentFormat.OpenXml中的.docx文件更新目录(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用DocumentFormat.OpenXml新的Word文档。 予加载模板文件,其中位于内容的表与表用画面的标志。我使用C#code此模板追加其他内容。 我这个文档发送给用户。

I create new word document using DocumentFormat.OpenXml. 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. I send this document to user.

当用户得到这个文件并打开它 - 表的内容不更新。 我找到了解决这一问题。我添加到我的code

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(新UpdateFieldsOnOpen(){瓦尔= TRUE});
  • mainPart.DocumentSettingsPart.Settings.Append(new UpdateFieldsOnOpen() { Val = true });

但是,当用户将获得该文件,并会打开它,他得到微软Word消息您想更新的领域?

But when user will get the document and will open it he get the message from MS Word "You wanna update fields?".

有没有其他的方法来生成目录或内容更新表没有任何消息给用户?

Is there any other way to generate table of contents or update table of contents without any message to user?

推荐答案

我回答我的问题: <一href="http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f53a939-f50e-423d-90fa-1f3c58945a6e" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/worddev/thread/7f53a939-f50e-423d-90fa-1f3c58945a6e

您现在看到的原因是,这是一种安全措施   几年前引入。可能的话,你可以燮preSS的消息   使用下面的知识库文章中描述的注册表项。您   然而需要要注意,这可能会降低系统的安全性。

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.

下面的博客文章介绍了正确的方法来更新   TOC: http://support.microsoft.com/kb/330079

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.

这篇关于使用DocumentFormat.OpenXml中的.docx文件更新目录(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆