2013-03-05 96 views
0

我使用poi-ooxml 3.9從excel模板生成發票報告,我用db存儲。我在表格末尾有公式,可以進行總計和其他稅務計算。POI公式評估器不工作

cell D30 =SUM(D22:D28) 
cell D31 =D30*0.12 
cell D32 =D31*0.02 
cell D33 =D31*0.01 
cell D35 =SUM(D30:D33) 

之前我寫的表到一個新的文件,我評價公式,但沒有任何工程。下面的代碼用於評估公式。每次將值寫入單元格或僅在操作結束時,是否需要評估公式?

String formulaCells[] = { "D30", "D31", "D32", "D33", "D35" }; 
FormulaEvaluator formulaEvaluator = workBook.getCreationHelper() 
     .createFormulaEvaluator(); 
Sheet sheet = workBook.getSheetAt(0); 
for (String cellRef : formulaCells) { 
CellReference ref = new CellReference(cellRef); 
Row actualRow = sheet.getRow(ref.getRow()); 
Cell cell = actualRow.getCell(ref.getCol()); 
if (cell != null) { 
// here I evaluate the formula  
formulaEvaluator.evaluateFormulaCell(cell); 

我錯過了什麼?

注意:只有打開生成的工作表並在每個單元格中按回車,公式纔會被評估!

回答

1

您確定您的手機已添加爲號碼嗎?

如果沒有,嘗試做這樣的事情:

if(type.equals("String")) { 
    cell.setCellValue (value.toString()); 
} else if (type.equals("int")) { 
    cell.setCellValue(Integer.parseInt(value.toString())); 
} else if (type.equals("double")) { 
    cell.setCellValue(Double.parseDouble(value.toString())); 
} 
+0

是的,你說得對!問題是我已經設置了所有的值(字符串)。謝謝! :-) – 2013-03-05 09:39:32