2010-11-15 233 views
3

我为我的应用程序使用Apache poi3.5和java 1.6。在这里,我有一个问题,使用公式...如何使用apache poi获取公式单元格值(数据)

我的单元格有公式(sheet2!C10)和该单元格内的数据是字符串类型...如何访问该单元格也要显示公式。

我的单元格有公式(sheet2!C11),并且此单元格内的数据是数字类型...如何访问该单元格也要显示公式。

我的单元格有公式(sheet2!C10),并且此单元格内的数据是日期类型...如何访问该单元格并且还想显示公式。

回答

5
System.out.println("Formula Cell value :" + org.apache.poi.ss.usermodel.DataFormatter dataFormatter.formatCellValue(cell, formulaEvaluator)); 

它将返回式单元值作为字符串...

7

对于任何式电池,使用poi3.8。

Workbook xlsWorkbook = null; 
Cell cell = null; 

FormulaEvaluator formulaEval = xlsWorkbook.getCreationHelper().createFormulaEvaluator(); 
String value=formulaEval.evaluate(cell).formatAsString(); 
相关问题