生成Open XML Word文档后自动更新公式字段 [英] Automatically update formula field after generating Open XML Word document

查看:100
本文介绍了生成Open XML Word文档后自动更新公式字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OpenXML SDK生成Word文档的库,该库的功能之一是生成在最后一行具有公式的表(例如SUM(ABOVE)).

I have a library that generates Word documents using the OpenXML SDK, one of the functionalities of the library is the generation of tables with formulas on the last row (such as SUM(ABOVE)).

Word内置了这些功能,但是在生成文档时,我必须假定计算机上未安装Word.

Word has these functions built-in, but when generating the document I have to assume that Word isn't installed on the machine.

问题是,如果我仅生成表格和公式字段,则在打开文档时不会自动更新它,用户将不得不打开文档并手动选择更新字段"以使函数计算.

The problem is that if I just generate the table and the formula field, it won't be updated automatically when the document is opened, the user would have to open the document and manually select "update field" for the function to be calculated.

代码中有什么方法可以做到这一点(而不必手动计算函数)?

Is there any way to do this within the code (without having to calculate the function manually)?

推荐答案

不,这是设计使然.有关详细信息,请参见在打开,重新分页或打印文档时会更新哪些字段.

No, this is by design. See Which fields are updated when you open, repaginate, or print document for details.

这同样适用于任何手动输入(例如,如果您在A1中有10个,在A2中有10个,在A3中插入了=SUM(ABOVE),那么您将有20个.但是,如果将A1更改为15,则A3不会更新除非并且直到您手动操作为止.)

This true of any manual input as well (for example if you had 10 in A1, 10 in A2, inserted =SUM(ABOVE) in A3, you'd have 20. But if you changed A1 to 15, A3 would not update automatically unless and until you manually did so).

解决此问题的唯一方法是创建一个加载项(VSTO,VBA等)以在客户端计算机上接收Document_Open事件,并运行一些代码以更新所有字段或在服务器上创建一个Interop应用程序,打开文档,用一些代码进行渲染,然后将其保存回去,然后再发送.

The only ways around this are to create an add-in (VSTO, VBA, etc.) to sink the Document_Open event on client machines and run some code to update all fields or create an Interop app on the server that opens the doc, renders it with some code and then saves it back before sending it on further.

这篇关于生成Open XML Word文档后自动更新公式字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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