Skip to content

Commit

Permalink
Merge pull request #167 from DDS-GmbH/fix/skip-out-of-window-cells
Browse files Browse the repository at this point in the history
Skip out-of-window cells on formula evaluation
  • Loading branch information
AntonOellerer committed Sep 29, 2022
2 parents 22f327a + 005e3e6 commit 9c76817
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '1.5.2'
version = '1.5.3'

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFFormulaEvaluator;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
Expand All @@ -42,7 +42,6 @@ public class SXSSFWriter implements ExcelWriter {
private final Path path;
private final SXSSFWorkbook workbook;
private final CreationHelper creationHelper;
private final FormulaEvaluator formulaEvaluator;
/**
* Maps the {@link CellStyle} objects of the old workbook to the new ones.
*/
Expand All @@ -59,7 +58,6 @@ public class SXSSFWriter implements ExcelWriter {
public SXSSFWriter(Path path) {
workbook = new SXSSFWorkbook();
this.creationHelper = workbook.getCreationHelper();
this.formulaEvaluator = creationHelper.createFormulaEvaluator();
this.path = path;
}

Expand Down Expand Up @@ -211,7 +209,7 @@ public void addRowOffset(int size) {

@Override
public void recalculateFormulas() {
formulaEvaluator.evaluateAll();
SXSSFFormulaEvaluator.evaluateAllFormulaCells(workbook, true);
}

private CellStyle copyCellStyle(CellStyle cellStyle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,20 @@ void xlsxQuotesBlockPlaceholder() throws InterruptedException, IOException {
assertThat(firstSheet.row(0).cell(0).stringValue(), equalTo(QuotesBlockPlaceholder.quotes.get("marx")));
assertThat(firstSheet.row(0).cell(1).stringValue(), equalTo(QuotesBlockPlaceholder.quotes.get("engels")));
}

@Test
void evaluatesLargeDocument() throws InterruptedException {
// Assemble
Template template = Template.fromClassPath("/templates/excel/LargeTemplate.xlsx")
.orElseThrow();
PlaceholderResolver resolver = new ReflectionResolver(SampleModelData.PICARD_PERSON);

// Act
Document document = template.startGeneration(resolver);
document.blockUntilCompletion(60000L); // 1 minute

// Assert
assertThat(document.completed(), is(true));

}
}
Binary file not shown.

0 comments on commit 9c76817

Please sign in to comment.