如何通过 XSSF 事件 API 评估 Excel 公式 [英] How to evaluate a excel formula through XSSF event API
问题描述
我正在使用 Apache POI 的事件 API 读取 XLSX 文件,即我通过 SAX 解析器读取 XLSX 表的内容.我想知道如何使用 XSSF 事件 API 获取公式的计算值.
I am reading XLSX files using event API of Apache POI, i.e I read the contents of the XLSX sheet through a SAX Parser. I want to know how can we get the computed value of a formula by using XSSF event API.
我知道的方法是使用 FormulaEvaluator
类.但是由于 formulaEvaluator 采用 Workbook 类的实例,我不想使用这种方法.(我正在读取包含 100 万行和 100 列的 Excel 文件,因此如果我创建该 Excel 的 Workbook 对象,我的应用服务器内存不足,因此我使用的是事件 API)
The way I know to do this is by using the FormulaEvaluator
class. But since formulaEvaluator takes an instance of Workbook class I don't want to use this approach. (I am reading Excel files containing a million rows and 100 columns so if I create a Workbook object of that Excel my app server goes out of memory and hence I am using Event API)
如何在没有 Workbook 实例的情况下在事件解析中进行评估?
How can I do the evaluation in event parsing, without a Workbook instance?
推荐答案
通常缓存的值会和单元格一起写入,所以你可以直接读取(不需要评估)
Generally the cached value will be written with the cell, so you can just read that (no need to evaluate)
以这个公式单元格为例:
Taking this formula cell as an example:
<c r="B10">
<f>SUM(B1:B9)</f>
<v>4995</v>
</c>
您读取 f 值以获取公式本身,或者仅读取 v 值以查看 excel 上次接触文件时公式的计算结果.无需评价!
You read the f value to get the formula itself, or just read the v value to see what the evaluation of the formula was when excel last touched the file. No need to evaluate!
这篇关于如何通过 XSSF 事件 API 评估 Excel 公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!