How to evaluate a excel formula through XSSF event API

末鹿安然 提交于 2019-12-01 04:48:08

问题


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.

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)

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


回答1:


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!



来源:https://stackoverflow.com/questions/5945959/how-to-evaluate-a-excel-formula-through-xssf-event-api

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