I am generating xlsx files and would like to not have to compute the values of all formulae during this process.
That is, I would like to set <v>
to 0 (or omit it) for cells with an <f>
, and have Excel fill in the values when it is opened.
One suggestion was to have a macro run Calculate
on startup, but have been unable to find a complete guide on how to do this with signed macros to avoid prompting the user. A flag you can set somewhere within the xlsx would be far better.
Edit: I'm not looking for answers that involve using Office programs to make changes. I am looking for file format details.
In the Excel for the web spreadsheet, click the Formulas tab. Next to Calculation Options, select one of the following options in the dropdown: To recalculate all dependent formulas every time you make a change to a value, formula, or name, click Automatic. This is the default setting.
Automatic (default) - tells Excel to automatically recalculate all dependent formulas every time any value, formula, or name referenced in those formulas is changed. Automatic Except for Data Tables - automatically recalculate all dependent formulas except data tables.
The Python module XlsxWriter sets the formula <v>
value to 0 (unless the actual value is known) and the <calcPr>
fullCalcOnLoad
attribute to true in the xl/workbook.xml
file:
<calcPr fullCalcOnLoad="1"/>
This works for all Excel and OpenOffice, LibreOffice, Google Docs and Gnumeric versions that I have tested.
The place it won't work is for non-spreadsheet applications that cannot re-calculate the formula value such as file viewers.
If calculation mode is set to automatic, Excel always (re)calculates workbooks on open.
So, just generate your files with calculation mode set to "Automatic".
In xl/workbook.xml
, add following node to workbook node:
<calcPr calcMode="auto"/>
Also check Description of how Excel determines the current mode of calculation.
You can use macros as suggested, however you will create a less secure and less compatible workbook without avoiding user interaction to force calculation.
If you opt by using VBA, you may Application.Calculate
in Workbook_Open
event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With