乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>POI</em>设置excel的公式-poi excel设置公式,poi excel

<em>POI</em>设置excel的公式-poi excel设置公式,poi excel

作者:乔山办公网日期:

返回目录:excel表格制作


针对此问题,写了一个测试,代码如下:package cn.fory.formula;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class TestFormula {/*** 测试POI处理公式** 问题描述:通过POI导入的数据后,引用导入数据的原有公式单元格不能显示出来,需要重新定位到公式单元* 格然后重新转入公式才行成得结果** 解决e799bee5baa6e997aee7ad94e4b893e5b19e339办法:重新对公式单元格设置公式** 相关文件:test.xls文件中手工设置单元格B2=C2+D2**/public static void main(String[] args) throws FileNotFoundException {POIFSFileSystem fs;try {fs = new POIFSFileSystem(new FileInputStream("test.xls"));HSSFWorkbook wb = new HSSFWorkbook(fs);HSSFSheet sheet = wb.getSheet("Sheet1");HSSFRow row = sheet.getRow((short) 1);HSSFCell cell = row.getCell((short) 2);cell.setCellValue((short) 5);cell = row.getCell((short) 3);cell.setCellValue((short) 40);HSSFCell cell1 = row.getCell((short)1);if (HSSFCell.CELL_TYPE_FORMULA == cell1.getCellType()) {//取得公式单元格的公式,重新设置cell1.setCellFormula(cell1.getCellFormula());}FileOutputStream fileOut = new FileOutputStream("test.xls");wb.write(fileOut);fileOut.close();

有一excel文件, A1 = 10 A2 = 20 A3 = a1+a2; 使用POI的getNumericCellValue()取得A1的值10,A2的值为20,没有问题. 可是取不到A3的值,...
你用绝对引用试试 sum($a$2:$a$6)

cell.setCellFormula("A1-B1-C1");

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网