From c59b99c20e85335218eee37c59cc051b0e5cd3cf Mon Sep 17 00:00:00 2001 From: Anton Oellerer <13524304+AntonOellerer@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:52:12 +0200 Subject: [PATCH] Catch exceptions when recalculating formulas This commit catches exceptions thrown when recalculating formulas. Additionally, `workbook#forceFormulaRecalculation` is set to true so that the user is prompted to recalculate all formulas upon opening the document. --- build.gradle | 2 +- .../jocument/impl/excel/implementations/SXSSFWriter.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ff2ebfa..0e2aaf5 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group 'com.docutools' -version = '2.0.0' +version = '2.0.1' java { toolchain { diff --git a/src/main/java/com/docutools/jocument/impl/excel/implementations/SXSSFWriter.java b/src/main/java/com/docutools/jocument/impl/excel/implementations/SXSSFWriter.java index 62484d9..6abed9b 100644 --- a/src/main/java/com/docutools/jocument/impl/excel/implementations/SXSSFWriter.java +++ b/src/main/java/com/docutools/jocument/impl/excel/implementations/SXSSFWriter.java @@ -280,7 +280,12 @@ public void addRowOffset(int size) { @Override public void recalculateFormulas() { - SXSSFFormulaEvaluator.evaluateAllFormulaCells(workbook, true); + try { + SXSSFFormulaEvaluator.evaluateAllFormulaCells(workbook, true); + } catch (Exception e) { + workbook.setForceFormulaRecalculation(true); + logger.error(e); + } } private CellStyle copyCellStyle(CellStyle cellStyle) {