Using Apache POI HSSF, how can I refresh all formula cells at once?

前端 未结 2 1067
无人共我
无人共我 2020-12-08 02:52

I am filling cells of an Excel file using Apache POI, and there are a lot of formula cells in the document. However, their values are not refreshed when I open the document

相关标签:
2条回答
  • 2020-12-08 03:15

    Sure. Refreshing all the formulas in a workbook is possibly the more typical use case anyway.

    If you're using HSSF, call evaluatorAllFormulaCells:

     HSSFFormulaEvaluator.evaluateAllFormulaCells(hssfWorkbook)
    

    If you're using XSSF, call evaluatorAllFormulaCells:

     XSSFFormulaEvaluator.evaluateAllFormulaCells(xssfWorkbook)
    

    More details are available on the poi website

    0 讨论(0)
  • 2020-12-08 03:35
    wb.setForceFormulaRecalculation(true);
    // replace "wb" with your HSSFWorkbook/XSSFWorkbook object
    

    https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html#setForceFormulaRecalculation-boolean-

    https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html#setForceFormulaRecalculation-boolean-

    0 讨论(0)
提交回复
热议问题