如何通过XSSF事件API评估excel公式

时间:2020-12-13 20:24:37

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.

我正在使用Apache POI, I的事件API读取XLSX文件。我通过SAX解析器读取XLSX表的内容。我想知道如何使用XSSF事件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)

我知道的方法是使用formula aevaluator类。但是因为formula aevaluator使用一个Workbook类的实例,所以我不想使用这种方法。(我正在读取包含100万行和100列的Excel文件因此,如果我创建这个Excel的工作簿对象,我的应用服务器就会耗尽内存,因此我使用事件API)

How can I do the evaluation in event parsing, without a Workbook instance?

在没有工作簿实例的情况下,如何在事件解析中进行计算?

1 个解决方案

#1


6  

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>

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!

你读f值来得到公式本身,或者只是读一下v值,看看excel最后一次触摸文件时的公式是什么。不需要评估!

#1


6  

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>

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!

你读f值来得到公式本身,或者只是读一下v值,看看excel最后一次触摸文件时的公式是什么。不需要评估!