0

I want to evaluate all formulas in a Workbook object. I know there are XSSFFormulaEvaluator and HSSFFormulaEvaluator for evaluating formulas in XSSFWorkbook and HSSFWorkbook. But the workbook object I have belongs to Workbook class.

I can use something like this,

XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook) workbook);

Is it ok to use this evaluator? Does it have any side effects to type-casting Workbook to XSSFWorkbook?

vaibhavvc1092
  • 3,067
  • 4
  • 19
  • 26

1 Answers1

2

This is covered in the Apache POI documentation on Formula evaluation - all you need to do is use the evaluateAll method, eg:

Workbook workbook = .... // Load/create the workbook

// Evaluate all formulas in it
workbook.getCreationHelper().createFormulaEvaluator().evaluateAll();
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • Can we add exceptions while evaluating All formulas? Like Cells or Formulas which should not be evaluated. My workbook is having formulas CELL and apache poi currently does not support this formula to it throws exception while evaluting the formula. Is there any work-around for this? – vaibhavvc1092 Jan 29 '16 at 07:31
  • If you look at the link to the docs I gave, you'll see how to evaluate on a cell by cell basis. Just catch and skip exceptions there from things you know won't work – Gagravarr Jan 29 '16 at 11:08