calculate cell values from formula programmatically in OpenXML sdk2

半城伤御伤魂 提交于 2019-12-02 00:28:01
spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true;  
spreadSheet.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true; 

this will work very well,when you open the Excel manually.but also can't Programmatically get the cell value with formulae.If you want to get the cell value by Open Xml SDK , have to open the excel file backgroud by Excel Application,and save the file. then can get the cell value programmatically.

This is the Information from Office Development Center:

How to automatically recalculate the formula value for cells in Spreadsheet?

A cell with a formula will store the cached value in the markup and show the cached value as the result. If the cell value referenced by the formula is changed programmatically, the cell with the formula has no idea of that change. The cached value of this formula is then obsolete, and should be updated. The automatic recalculation requires runtime layout functionality, which is not supported in the SDK. The workaround for this situation is to: delete the cached value of the formula cell, and then invoke Excel to recalculate the value for you at backend. The Excel service could help here.

Aside from writing your own parser to calculate the value of the cell, this is not currently possible. You could of course use automation under a service account to recalculate the formulae behind the scenes, but that can get messy fast.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!