Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Excel公式(使用Apache POI设置)不会自动计算_Java_Excel_Apache Poi - Fatal编程技术网

Java Excel公式(使用Apache POI设置)不会自动计算

Java Excel公式(使用Apache POI设置)不会自动计算,java,excel,apache-poi,Java,Excel,Apache Poi,我在Excel单元格Excel 2013中有以下公式 =IF(ROW()>(currentMonths+ROW($A$2)),D7-OFFSET(D7,-currentMonths,0),"") 我已经使用JavaApachePOI将公式写入Excel表。事实上,我已经使用JavaApachePOI将currentMonths从1循环到12,每次都重新计算工作表,这非常有效。问题是,当我在Excel中实际加载工作表时,重新计算就不起作用了 我用于在Java Apache POI中重新计算

我在Excel单元格Excel 2013中有以下公式

=IF(ROW()>(currentMonths+ROW($A$2)),D7-OFFSET(D7,-currentMonths,0),"")
我已经使用JavaApachePOI将公式写入Excel表。事实上,我已经使用JavaApachePOI将currentMonths从1循环到12,每次都重新计算工作表,这非常有效。问题是,当我在Excel中实际加载工作表时,重新计算就不起作用了

我用于在Java Apache POI中重新计算12个月的代码如下:

//loop over 12 months
for (int currentMonth = 1; currentMonth <= 12; currentMonth++) {

    //set the month
    CellUtil.getCell(r, 1).setCellValue(currentMonth);

    //recalculate the sheet
    wb.getCreationHelper().createFormulaEvaluator().evaluateAll();

    //get the result of the recalculation
    double result = CellUtil.getCell(r4, 25).getNumericCellValue();

    //and paste result
    Row r2 = CellUtil.getRow(currentMonth + 4, resultsSheet);
    CellUtil.getCell(r2, 1).setCellValue(result);
}

有人有什么想法吗?

如果您尝试按照重新计算该单元格,会发生什么?我编辑了我的问题,以描述Apache POI如何完美地重新计算工作表;问题是在Excel中打开图纸时,您如何重新计算?没有向问题添加代码来显示它?我已编辑问题以显示重新计算
=IF(ROW()>(currentMonths+ROW(Data!$A$2)),Data!D7-OFFSET(Data!D7,-currentMonths,0),"")