diff options
author | PJ Fanning <fanningpj@apache.org> | 2023-06-22 21:37:01 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2023-06-22 21:37:01 +0000 |
commit | 01208d5790afee3586c8073c750d9795efc02031 (patch) | |
tree | a0389c4d89be5a70976d022bbdf4c5038823ab65 /poi-ooxml | |
parent | e8505dc2080bea109258824623d0a5e8a679f0be (diff) | |
download | poi-01208d5790afee3586c8073c750d9795efc02031.tar.gz poi-01208d5790afee3586c8073c750d9795efc02031.zip |
[bug-66661] revert github-269 due to it breaking formulas with table references
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1910561 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
4 files changed, 8 insertions, 22 deletions
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 07f4d6d314..755da69e12 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,7 +29,6 @@ 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; @@ -493,19 +492,7 @@ public final class XSSFCell extends CellBase { if (wb.getCellFormulaValidation()) { XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(wb); //validate through the FormulaParser - 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); - } + FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex()); } CTCellFormula f; diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCell.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCell.java index 2d2b930598..ec06fa81f2 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCell.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFCell.java @@ -560,14 +560,13 @@ public final class TestXSSFCell extends BaseTestXCell { @Test public final void testCopyCellFrom_CellCopyPolicy_formulaWithUnregisteredUDF() { setUp_testCopyCellFrom_CellCopyPolicy(); - // this will format the formula string, srcCell.setCellFormula("MYFUNC2(123, $A5, Sheet1!$B7)"); // Copy formula verbatim (no shifting). This is okay because copyCellFrom is Internal. // Users should use higher-level copying functions to row- or column-shift formulas. final CellCopyPolicy policy = new CellCopyPolicy.Builder().cellFormula(true).build(); destCell.copyCellFrom(srcCell, policy); - assertEquals("MYFUNC2(123,$A5,Sheet1!$B7)", destCell.getCellFormula()); + assertEquals("MYFUNC2(123, $A5, Sheet1!$B7)", destCell.getCellFormula()); } @Test diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java index e8f2290935..887e23ae11 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java @@ -186,8 +186,8 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator { // Add another formula referencing these workbooks Cell cXSL_cell2 = rXSL.createCell(40); cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1"); - // it become [2] like the others - assertEquals("[2]Uses!$C$1", cXSL_cell2.getCellFormula()); + // TODO Shouldn't it become [2] like the others? + assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula()); assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell2).formatAsString()); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java index 6f49ef11cd..fc4a9c6032 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java @@ -400,10 +400,10 @@ public final class TestXSSFFormulaParser { } @Test - void testQuotedSheetNamesReference() { + void testQuotedSheetNamesReference() throws IOException { // quoted sheet names bug fix - Workbook[] wbs = new Workbook[]{new HSSFWorkbook(), new XSSFWorkbook()}; - for (Workbook wb : wbs) { + // see TestHSSFFormulaEvaluator equivalent which behaves a little differently + try (XSSFWorkbook wb = new XSSFWorkbook()) { Sheet sheet1 = wb.createSheet("Sheet1"); Sheet sheet2 = wb.createSheet("Sheet2"); Sheet sheet3 = wb.createSheet("Sheet 3"); @@ -438,7 +438,7 @@ public final class TestXSSFFormulaParser { formula = "SUM('Sheet1:Sheet2'!A1:B1)"; cell.setCellFormula(formula); cellFormula = cell.getCellFormula(); - assertEquals("SUM(Sheet1:Sheet2!A1:B1)", cellFormula); + assertEquals("SUM('Sheet1:Sheet2'!A1:B1)", cellFormula); // quoted sheet names with space cell = tempRow.createCell(4); |