Updating Formula Result
See original GitHub issueIt’s unclear from the documentation how I would go about doing this.
I want to read in an existing XLS file, update some values, and then get the new computed results of formulae.
For example, if I have this spreadsheet:
A1=3
A2=4
A3=7
A4=sum(A1:A3)
I’d like to update A3 to equal 8 and for A4’s value to then yield 15.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Replace a formula with its result - Microsoft Support
Replace formulas with their calculated values · Press F2 to edit the cell. · Press F9, and then press ENTER.
Read more >How to fix Excel formulas not calculating (Refresh Formulas)
1. Go to the Formulas tab. 2. Click on Calculation Options. 3. Set calculation settings to Automatic. Read other methods here, step-by-step.
Read more >Excel formulas not working, not updating, not calculating
Fixes and solutions for Excel formulas not working. See how to fix a formula that is not calculating or not updating automatically, ...
Read more >How to Fix Excel Formulas that are Not Calculating or Updating
There are three calculation options in Excel. Automatic Calculation means that Excel will recalculate all dependent formulas when a cell value ...
Read more >Excel Formulas Not Calculating? What to Check | Pryor Learning
When this option is set to automatic, Excel recalculates the spreadsheet's formulas whenever you change a cell value. This means that, if you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I discovered that Shift-F9 (“recalculate worksheet” in Excel) does not sufficiently recalculate the spreadsheet but that Ctrl-Shift-Alt-F9 (in Excel) does recalculate the spreadsheet successfully.
However, since I don’t want to have to do a recalculation in Excel, I found this work-around. I actually have calculated the results of the formulas in Node.js, so I tried the following.
// value is the value I want to set to the cell // cell is the cell object from the worksheet if (cell.value && typeof(cell.value) === “object” && cell.value.formula) { cell.value.result = value; // I would think this would work but it doesn’t } else { cell.value = value; }
However, when I try to set the result of a formula cell like that (above), it doesn’t seem to work. The result does not stick. If I print out the cell.value.result before and after, it is unchanged. (!?!) There seems to be some object magic happening on the value of a formula cell that I’m not understanding.
So I did the following instead, and it works perfectly. The new result shows up in Excel for the formula cell when the file is opened up.
// value is the value I want to set to the cell // cell is the cell object from the worksheet if (cell.value && typeof(cell.value) === “object” && cell.value.formula) { cell.value = { formula: cell.value.formula, // copy in the old formula from the old cell.value result: value // put the newly computed value in as the result }; } else { cell.value = value; }
IMPORTANT: This method does not cause Excel to recalculate the values of the formulas. For that, you still have to Enable Editing of the downloaded spreadsheet and press Ctrl-Shift-Alt-F9. This method merely allows that if you have computed the result of the formula correctly in Node.js, then you can set it so that Excel will display it when the file is first opened.
Yes - the library is not a replacement for Excel, it won’t calculate the results for you - at least not yet anyway.