Updating Fields while Assembling Word Processing Documents
Updating Fields while Assembling Word Processing Documents
Leave feedback
On this page
Updating fields
By default, fields in a Word Processing template (for example, =SUM(ABOVE) formulas in tables) keep the result values stored in the template. Apply the DocumentAssemblyOptions.UPDATE_FIELDS_AND_FORMULAS option to make the engine recalculate them while assembling the report.
The recipe
Set up the source template path
Set up the destination report path
Instantiate the DocumentAssembler class
Set the DocumentAssemblyOptions.UPDATE_FIELDS_AND_FORMULAS option
Generate the report
The template
The template contains a list of clients built from data and a table with a formula field in the last cell:
We provide support for the following clients:
<<foreach [in clients]>><<[Name]>>
<</foreach>>
constgroupdocs=require('@groupdocs/groupdocs.assembly');consttemplatePath="Update field.docx";constreportPath="Update field_report.docx";constassembler=newgroupdocs.DocumentAssembler();// Recalculate fields and formulas while assembling
assembler.setOptions(groupdocs.DocumentAssemblyOptions.UPDATE_FIELDS_AND_FORMULAS);constdataSource=newgroupdocs.JsonDataSource("clients.json");assembler.assembleDocument(templatePath,reportPath,newgroupdocs.DataSourceInfo(dataSource,"clients"));process.exit(0);
In the report, the Total cell shows the recalculated value 30,500 (the number format follows the current culture). Without the option, the field keeps the value that was stored in the template.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.