GemBox从电子表格或Flexcel检索计算值 [英] GemBox Retrieving Calculated Values From a Spreadsheet or Flexcel
问题描述
根据他们的文档:GemBox.Spreadsheet可以读取和写入公式,但不能计算公式结果.在MS Excel中打开XLS文件时,公式结果将自动计算.
因此,如果我创建带有一些注入值的电子表格并将其保存到磁盘(如果我在excel中打开文件,则可以看到计算出的值).
如果我在gembox中打开该文件并查找计算出的单元格值,则结果为0
flexcel中也存在相同的功能..无法从给定的单元格中检索计算出的值..它返回零..
所以我正在做的是:
- 打开现有的excel文件
- 将一些数字放入某些单元格
- 以不同的名称将文件保存到磁盘(也尝试使用相同的文件)
- 再次打开文件并查看作为计算单元格的合计列
该值始终为0.我在excel中打开文件.该值已按预期计算.
编辑28-09-2016:
我们发布了新版本的GemBox.Spreadsheet(4.1版),其中实现了对单元格公式计算的支持,计算示例.>
原始答案
GemBox.Spreadsheet当前仅支持由Excel计算的值(因此,如果文件由MS Excel保存,则我们可以读取公式值). GemBox.Spreadsheet没有自己的计算引擎.
要读取 XLS 格式的公式值,请使用接受XlsOptions
枚举的ExcelFile.LoadXls
重载,并使用XlsOptions.PreserveWorksheetRecords
或XlsOptions.PreserveAll
.
要读取 XLSX 格式的公式值,请使用ExcelFile.LoadXlsx
方法和XlsxOptions
枚举值XlsxOptions.PreserveKeepOpen
或XlsxOptions.PreserveMakeCopy
.
According to their docs: GemBox.Spreadsheet can read and write formulas, but can not calculate formula results. When you open a XLS file in MS Excel, formula results will be calculated automaticaly.
So if i create a spreadsheet with some injected values and save it to disk if i open the file in excel i can see the calculated values..
if i open that file in gembox and look up the calculated cell's values i get a result of 0
the same functionality exists in flexcel as well.. can't retrieve the calculated value from a given cell.. it returns zero..
So what I'm doing is:
- Open an existing excel file
- Putting some numbers in to some cells
- Saving the file to disk under a different name (tried with the same file too)
- Opening the file again and looking in the total column which is a calculated cell
The value is always 0.. I open the file in excel.. the value is calculated as expected.
EDIT 28-09-2016:
We have released a new version of GemBox.Spreadsheet (version 4.1) in which we implemented a support for cell formula calculation, see the version history page.
Also, you can find the calculation example here.
ORIGINAL ANSWER
GemBox.Spreadsheet currently supports only values that are calculated by the Excel (so if file is saved by the MS Excel, we can read formula values). GemBox.Spreadsheet does not have its own calculation engine.
To read formula values in XLS format use ExcelFile.LoadXls
overload that accepts XlsOptions
enumeration and use XlsOptions.PreserveWorksheetRecords
or XlsOptions.PreserveAll
.
To read formula values in XLSX format use ExcelFile.LoadXlsx
method with XlsxOptions
enumeration values XlsxOptions.PreserveKeepOpen
or XlsxOptions.PreserveMakeCopy
.
这篇关于GemBox从电子表格或Flexcel检索计算值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!