We have a document with formulas and references to the results of thos calculations. We have to call updateFields three times to get all the forward references to properly update. The method updateFields does not take an argument and does not return a value. Is there some other method that will update all the forward references properly or some way to tell when I can stop calling updateFields because everything has been resolved?
I got the value three by trying two and then three and at three all the fields were properly updated.
Thanks.
Hi Scott,
Please accept my apologies for late response. It would be great if you please share your document for investigation purposes.
When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.
Please read following documentation links for your kind reference.
https://docs.aspose.com/words/net/working-with-fields
https://docs.aspose.com/words/net/updating-and-removing-a-field/
I understand that I need to call updateFields to update the values. The problem is that I have one set of calculated values at the end of the document, one set of calculated values in the middle of the document that references the values at the end of the document, and one set of calculated values in the begining of the document that references values in the middle of the document.
It looks like Aspose.Words is doing a single pass from start to finish for updateFields. If I call it once only the values at the end of the document are updated. If I call it twice then the ones at the end and the middle are updated. When I call it three times I get all of the values updated. From the results of calling once, twice, and three times I can see first the values at the end of the document are updated, then the values in the middle, and finally the values at the top.
When processing statements it is often the case that there is a summary at the top of the document, some aggragate values in the middle, and the detail lines at the end. Depending on the type of statement it can have multiple layers of calculated values each feading the other. It would be troublesome to try and figure out for each document how many times I have to call updateFields to get all the values calcuated correctly, I was hoping there was some method I just didn’t know about and was unable to find in my searches or some way I could get feedback from updateFields to let me know whan everything had been updated. Otherwise I have call it a large number of time, like 10 or something, to make sure that even the most complex documents will render correctly or I have to work out how many times I have call updateFields for each document type and code that in to the program. This would then most likely fail in strange ways if someone adds a new document type or changes an existing document type to require more calls to updateFields.
Hi Scott,
Thanks for sharing the details. It seems that you are using Range.UpdateFields method instead of Document.UpdateFields method. Please call Document.UpdateFields method in your code. If you still face problem, please share your document and code for investigation purposes.
Document doc = new Document(MyDir + "Document.doc");
doc.UpdateFields();