Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poi Formula evaluation

I am facing difficulties while reading formula cell values with POI

I have created formula cell as follows:

cell.setCellType(HSSFCell.CELL_TYPE_FORMULA); 
cell.setCellFormula("SUM(D8..F8)");

And I am reading it as follow:

double formulaCellValue = row.getCell((short) 7).getNumericCellValue();

When read this way(using getNumericCellValue()), I am always getting the value of 0.0.

Any quick help in this regard would be highly appriciated.

like image 561
Fahmi Avatar asked Apr 21 '11 16:04

Fahmi


People also ask

What is the formula of evaluation?

The Evaluate Formula feature walks you through each argument in a formula to help identify and fix any mistakes. You can also use it to understand complex formulas, seeing how each part of a nested function is calculated to reach the final result.

What is Poi method?

POI stands For “Poor Obfuscation Implementation”. Apache POI is an API provided by Apache foundation which is a collection of different java libraries. These libraries gives the facility to read, write and manipulate different Microsoft files such as excel sheet, power-point, and word files.

What is formula evaluator?

public interface FormulaEvaluator. Evaluates formula cells. For performance reasons, this class keeps a cache of all previously calculated intermediate cell values. Be sure to call clearAllCachedResultValues() if any workbook cells are changed between calls to evaluate~ methods on this class.


1 Answers

After you're done setting all your formulas, you need to trigger a recalculation. See the why evaluate docs for the background on why you need to do it, and the Evaluation docs for details. Quick answer is you'd likely want to do something like:

HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook);

Don't call it until you're done adding / editing all your cells though! You can also trigger the evaluation of just one cell, see the docs for details of the various options if you need full control.

like image 60
Gagravarr Avatar answered Sep 25 '22 20:09

Gagravarr