diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-11-02 18:59:18 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-11-02 18:59:18 +0000 |
commit | 1328893212c74d4bf41e408b04d28e0928a29d80 (patch) | |
tree | 487f50bf80e84176c2a567066cbe2ac35d45836f /poi-ooxml/src/main/java | |
parent | d9b6f799a648d5b55401c2e4a41c60e99782abb1 (diff) | |
download | poi-1328893212c74d4bf41e408b04d28e0928a29d80.tar.gz poi-1328893212c74d4bf41e408b04d28e0928a29d80.zip |
[github-269] more work on external workbook links (formulas). Thanks to @aspojo. This closes #269
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894695 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main/java')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java | 1 | ||||
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java | 15 |
2 files changed, 15 insertions, 1 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java index d18177c032..4095bf78b7 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java @@ -61,6 +61,7 @@ public class SXSSFCreationHelper implements CreationHelper { @Override public SXSSFFormulaEvaluator createFormulaEvaluator() { + return new SXSSFFormulaEvaluator(wb); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java index a1d33c9600..d7ed668d1f 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java @@ -29,6 +29,7 @@ import org.apache.poi.ss.formula.FormulaRenderer; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.SharedFormula; import org.apache.poi.ss.formula.eval.ErrorEval; +import org.apache.poi.ss.formula.ptg.ErrPtg; import org.apache.poi.ss.formula.ptg.Ptg; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellBase; @@ -474,7 +475,19 @@ public final class XSSFCell extends CellBase { if (wb.getCellFormulaValidation()) { XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); //validate through the FormulaParser - FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex()); + Ptg[] ptgs = FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex()); + // Make its format consistent with Excel. + // eg: "SUM('Sheet1:Sheet2'!A1:B1)" will be trans to "SUM(Sheet1:Sheet2!A1:B1)" + boolean hasError = false; + for (Ptg ptg : ptgs) { + if (ptg instanceof ErrPtg) { + hasError = true; + break; + } + } + if (!hasError) { + formula = FormulaRenderer.toFormulaString(fpb, ptgs); + } } CTCellFormula f; |