如何使用 Apache POI 在单元格中设置公式? [英] How to set formulas in cells using Apache POI?
本文介绍了如何使用 Apache POI 在单元格中设置公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用 Apache POI for Java 在单元格中设置公式.
I am currently using Apache POI for Java to set formulas in cells.
但是在我运行程序并打开我创建和处理的 Excel 文件后,带有公式的单元格将公式包含为字符串,而不是公式应该返回的值.
But after I run the program and open the Excel file that I created and processed, the cells with the formula include the formula as a string, rather than the value the formula should have returned.
推荐答案
HSSFCell
对象有方法 .setCellType
和 .setCellFormula
需要这样调用:
The HSSFCell
object has methods .setCellType
and .setCellFormula
which you need to call like this:
// "cell" object previously created or looked up
String strFormula= "SUM(A1:A10)";
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula(strFormula);
这篇关于如何使用 Apache POI 在单元格中设置公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文