在多表格excel生成中使用JXLS excel sum函数无法正常工作

时间:2015-09-16 14:03:26

标签: java excel jxls

我正在创建一个包含2个工作表的Excel工作簿;它必须计算两个工作表中列的总和,但它计算总和将它放在错误的工作表上(如计算第一个工作表的总和并将该总和放在第二个工作表中,并将第二个工作表总和放在第一个工作表中)

Transformer transformer =TransformerFactory.createTransformer(is, os);
    XlsArea xlsArea=new XlsArea("Report!A1:N12",transformer);
    XlsArea entityArea= new XlsArea("Report!A1:N11",transformer);
    EachCommand entityEachCommand=new EachCommand("entity","entities",entityArea,new SimpleCellRefGenerator());
    XlsArea reportDataArea=new XlsArea("Report!A10:N10",transformer);
    EachCommand reportDataEachCommand=new EachCommand("data","entity.reportDatas",reportDataArea);
    xlsArea.addCommand(new AreaRef("Report!A1:N11"),entityEachCommand);
    entityArea.addCommand(new AreaRef("Report!A10:N10"),reportDataEachCommand);
    Context context=new Context();
    context.putVar("entities",reportData);
    xlsArea.applyAt(new CellRef("Report!A1"),context);
    reportDataArea.processFormulas();
    transformer.write();
}

1 个答案:

答案 0 :(得分:0)

默认情况下,JXLS使用FastFormulaProcessor,速度更快,但在某些情况下可能会导致公式损坏。如果遇到问题,请尝试切换到StandardFormulaProcessor(请参阅http://jxls.sourceforge.net/reference/formulas.htmlhttps://bitbucket.org/leonate/jxls/issues/44/multisheet-bug-in-sum-formulas-arbitrary):

        xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
        xlsArea.processFormulas();