views:

155

answers:

1

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 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)?

+2  A: 

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

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).

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.

Otaku
That's what I thought, the only problem I have is that I cannot assume the user has Word installed on the machine, therefore I'll have to stick with the manual calculation (luckily the number of functions is limited). Thanks!
willvv