POI:Excel计算公式的再计算
2011-08-30 22:02
447 查看
前面在用POI操作Excel的时候,对于Excel的公式再计算使用的是
Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened.
正常情况下都能够正常计算。
但是如果Excel模板的计算方式是手动的时候,貌似就不灵性了。
无奈之下查询POI的API,实际上有两个方式实现公式再计算。
1. Re-evaluate formuals with POI's FormulaEvaluator:
2. Delegate re-calculation to Excel. The application will perform a full recalculation when the workbook is opened:
即使Excel模板的计算方式是手动的时候,也能够实现公式再计算。这是因为FormulaEvaluator是事先计算,而setForceFormulaRecalculation是打开Excel的时候计算。
setForceFormulaRecalculation(boolean value)
Control if Excel should be asked to recalculate all formulas on this sheet when the workbook is opened.
正常情况下都能够正常计算。
但是如果Excel模板的计算方式是手动的时候,貌似就不灵性了。
无奈之下查询POI的API,实际上有两个方式实现公式再计算。
1. Re-evaluate formuals with POI's FormulaEvaluator:
Workbook wb = WorkbookFactory.create(new FileInputStream("workbook.xls")); Sheet sh = wb.getSheetAt(0); sh.getRow(0).getCell(0).setCellValue(2); // set A1=2 wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
2. Delegate re-calculation to Excel. The application will perform a full recalculation when the workbook is opened:
Workbook wb = WorkbookFactory.create(new FileInputStream("workbook.xls")); Sheet sh = wb.getSheetAt(0); sh.getRow(0).getCell(0).setCellValue(2); // set A1=2 wb.setForceFormulaRecalculation(true);
即使Excel模板的计算方式是手动的时候,也能够实现公式再计算。这是因为FormulaEvaluator是事先计算,而setForceFormulaRecalculation是打开Excel的时候计算。
相关文章推荐
- POI操作Excel:密码保护和公式再计算
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- 使用POI处理Excel中公式不能自动计算出来的问题
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- poi 操作 excel 里面设置的公式不会自动计算 需要双击才会触发
- poi读取excel模板,填充内容并导出,支持导出2007支持公式自动计算
- 使用poi更新excel,有公式的cell不计算的解决办法
- 小结:POI写Excel公式(函数)及从Excel中读取公式计算值
- java poi读取Excel里面含有公式的单元格的值
- EXCEL计算公式之:excel跨文件、跨Sheet的合并计算公式
- python在excel插入几个值之后,刷新表格公式的计算结果,怎么弄啊
- 使用POI操作Excel时对事先写入模板的公式强制执行
- 使用Excel中的公式计算日期
- Excel中计算个人所得税的公式
- Excel个人所得税简洁计算公式
- Excel输入计算公式时不想输等号=
- Poi处理Excel时公式不能更新的问题
- Excel关于日期计算的公式技巧
- oms数据通过excel模板导出excel文件,同时可在excel模板中添加计算公式