updatefieldsonopen openxml SDK的替代方案 [英] Alternative for updatefieldsonopen openxml SDK

查看:176
本文介绍了updatefieldsonopen openxml SDK的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:使用OpenXML SDK 2.5更新内容表



我将使用OpenXML / c#在文档之间添加内容。 TOC已存在于文档中,我只想以编程方式更新它。怎么做 ?



提前致谢:)



我的尝试:



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



我使用这个来更新现有的TOC,但是当用户打开文档时,会弹出一个弹出窗口(你想更新字段......就像这样)。



如何抑制它?(我已经通过了MSDN链接。它似乎有风险)否则,是否有像fieldupdate那样的替代方法来生成文件时更新TOC?

scenario: update Table of content using OpenXML SDK 2.5

I will be adding contents in between the document using OpenXML/c#. TOC is already present in the document, I just want to update it programmatically. How to do it ?

Thanks in advance :)

What I have tried:

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

I update existing TOC using this, But when user opens the document, gets a popup(Would you like to update fields ...like this).

How to suppress that ?(I've gone through MSDN links. It seems to be risky) else, is there any alternative like fieldupdate thing to update TOC while generating document?

推荐答案

下面的代码可用于通过宏弹出自动更新内容表



Below code will work for update the table of content automatically with Macro popup

DocumentSettingsPart settingsPart = mainPart.Document.MainDocumentPart.GetPartsOfType<DocumentSettingsPart>().First();
                // Create object to update fields on open
                UpdateFieldsOnOpen updateFields = new UpdateFieldsOnOpen();
                updateFields.Val = BooleanValues.True;
                // Insert object into settings part.
                settingsPart.Settings.PrependChild<UpdateFieldsOnOpen>(updateFields);
                settingsPart.Settings.Save();


只有更简单的解决方案才能达到这个目标。宏。

自这些页面编号由文字处理器渲染引擎处理,我们无法以编程方式预测或添加页码。



可以抑制Macro弹出窗口,但是它很忙,因为你已达到对计算机有害的注册表级别。所以我建议你用宏完成它。
Only easier solution to achieve this is "Macro".
Since these page numberings are taken care by the word processor rendering engine, we cannot predict or add page number programmatically.

It's possible to suppress the Macro pop up, but it's hectic because you've hit registry level which is harmful to the computer. So I'd suggest you accomplish it with macro.


这篇关于updatefieldsonopen openxml SDK的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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