Java 爪哇及;Excel-公式更新
我正在使用ApachePOI将数据保存到excel文件中。基本数据保存得很好,但我还需要使用公式 它在中添加公式,但在刷新单元格(单击进入并按enter键)之前不会计算公式 我用来创建单元格的代码。删除了不相关的代码Java 爪哇及;Excel-公式更新,java,apache-poi,Java,Apache Poi,我正在使用ApachePOI将数据保存到excel文件中。基本数据保存得很好,但我还需要使用公式 它在中添加公式,但在刷新单元格(单击进入并按enter键)之前不会计算公式 我用来创建单元格的代码。删除了不相关的代码 public void writeExcel(ClassManager cm) throws FileNotFoundException, IOException { setupRows(); workbook.setForceFormulaRecalculatio
public void writeExcel(ClassManager cm) throws FileNotFoundException, IOException {
setupRows();
workbook.setForceFormulaRecalculation(true);
FileOutputStream outputStream = new FileOutputStream(fileLocation);
workbook.write(outputStream);
workbook.close();
}
public void setupRows() {
setupRow15();
}
public void setupRow15() {
int start = 2;
Row row = sheet.createRow(16);
// Create 1st Cell
Cell cell = row.createCell(0);
cell.setCellValue("templateId = ");
for (int i = 0; i < classes.size(); i++) {
// Get class
Classes c = classes.get(i);
// Create cell
cell = row.createCell(start);
// Set contents
cell.setCellFormula("IF(C3=\"\",\"\",CONCAT($A17,$B17,C" + (start + 1) + ",$B17,$A$16))");
start++;
}
}
public void writeExcel(ClassManager cm)抛出FileNotFoundException、IOException{
setupRows();
工作簿.SetForceFormulaReculation(真);
FileOutputStream outputStream=新的FileOutputStream(fileLocation);
workbook.write(outputStream);
workbook.close();
}
公共void setupRows(){
设置行15();
}
公共空间设置第15行(){
int start=2;
Row Row=sheet.createRow(16);
//创建第一个单元格
Cell Cell=row.createCell(0);
cell.setCellValue(“templateId=”);
对于(int i=0;i
这将导致公式在设置所有公式后运行解决方案
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
for (Row r : sheet) {
for (Cell c : r) {
evaluator.evaluateFormulaCell(c);
}
}
你复习了吗?(旁注:你问题的最后一句是否不完整?)