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);
我错过了什么?
注意:只有打开生成的工作表并在每个单元格中按回车,公式才会被评估!
是的,你说得对!问题是我已经设置了所有的值(字符串)。谢谢! :-) – 2013-03-05 09:39:32