简体   繁体   English

下载后的Apache POI公式的初始计算

[英]Apache POI initial calculation of formula after download

I use Apache POI for creating a Excel File. 我使用Apache POI创建Excel文件。 There are two diffrent sheets. 有两个不同的表。 Sheet 1 is a template with some formulars. 表格1是带有一些公式的模板。 In Sheet 2 i want to get the the value of one cell in Sheet 1. This is the Excel-formula to get the value from Sheet 1: 在工作表2中,我想获取工作表1中一个单元格的值。这是从工作表1中获取值的Excel公式:

=IF(Sheet1!D7="";"";Sheet1!D7)

But when I put some text in D7 with 但是当我在D7中输入一些文字时

  cell = worksheet1.getRow(6).getCell(3);
  cell.setCellValue("SomeText");

it wont take over the value to Sheet 2. If i click into D7 and use enter, Sheet2 will take the value, but i want, that apache poi do this. 它不会接管工作表2的值。如果我单击D7并使用enter,Sheet2将接管该值,但是我想让该Apache Poi执行此操作。

How can I handle this? 我该如何处理?

You have to evaluate the formula before final output. 您必须在最终输出之前评估公式。

Use this in order to evaluate all formulas. 使用此为了评估所有公式。

FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
formulaEvaluator.evaluateAll();

Use this in order to evaluate the formula of a specific cell 使用它来评估特定单元格的公式

FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateFormulaCell(cell);

And then write the file in the stream 然后在流中写入文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM