如何设置使用Apache POI单元格的公式? [英] How to set formulas in cells using Apache POI?

查看:728
本文介绍了如何设置使用Apache POI单元格的公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的Apache POI 对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆