]> source.dussan.org Git - poi.git/commitdiff
revert github-267 due to broken tests
authorPJ Fanning <fanningpj@apache.org>
Mon, 25 Oct 2021 10:11:04 +0000 (10:11 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 25 Oct 2021 10:11:04 +0000 (10:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894550 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFormulaParser.java
poi/src/main/java/org/apache/poi/ss/formula/FormulaParser.java
poi/src/main/java/org/apache/poi/ss/formula/ptg/ExternSheetNameResolver.java
poi/src/test/java/org/apache/poi/hssf/model/TestFormulaParser.java
poi/src/test/java/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

index fcdd530be8567c8a3fe3fe6de35512f80f914355..a1d33c9600a31462112d085f2ac3aa85eef17b26 100644 (file)
@@ -474,10 +474,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)"
-            formula = FormulaRenderer.toFormulaString(fpb, ptgs);
+            FormulaParser.parse(formula, fpb, formulaType, wb.getSheetIndex(getSheet()), getRowIndex());
         }
 
         CTCellFormula f;
index 120184b68143a69c1fd60c28303cbe6588c710ab..7b56cf8965cfa1c42319da9474ee6799a6b3c1f7 100644 (file)
@@ -723,49 +723,4 @@ public final class TestXSSFFormulaParser {
 
         wb.close();
     }
-
-    @Test
-    void testQuotedSheetNamesReference() {
-        // quoted sheet names bug fix (https://github.com/apache/poi/pull/267)
-        Workbook[] wbs = new Workbook[]{new HSSFWorkbook(), new XSSFWorkbook()};
-        for (Workbook wb : wbs) {
-            Sheet sheet1 = wb.createSheet("Sheet1");
-            Sheet sheet2 = wb.createSheet("Sheet2");
-            Sheet sheet3 = wb.createSheet("Sheet 3");
-
-            Row tempRow = sheet1.createRow(0);
-            tempRow.createCell(0).setCellValue(1);
-            tempRow.createCell(1).setCellValue(2);
-
-            tempRow = sheet2.createRow(0);
-            tempRow.createCell(0).setCellValue(3);
-            tempRow.createCell(1).setCellValue(4);
-
-            tempRow = sheet3.createRow(0);
-            tempRow.createCell(0).setCellValue(5);
-            tempRow.createCell(1).setCellValue(6);
-
-            Cell cell = tempRow.createCell(2);
-
-            // unquoted sheet names
-            String formula = "SUM(Sheet1:Sheet2!A1:B1)";
-            cell.setCellFormula(formula);
-            String cellFormula = cell.getCellFormula();
-            assertEquals(formula, cellFormula);
-
-            // quoted sheet names with no space
-            cell = tempRow.createCell(3);
-            formula = "SUM('Sheet1:Sheet2'!A1:B1)";
-            cell.setCellFormula(formula);
-            cellFormula = cell.getCellFormula();
-            assertEquals("SUM(Sheet1:Sheet2!A1:B1)", cellFormula);
-
-            // quoted sheet names with space
-            cell = tempRow.createCell(4);
-            formula = "SUM('Sheet1:Sheet 3'!A1:B1)";
-            cell.setCellFormula(formula);
-            cellFormula = cell.getCellFormula();
-            assertEquals(formula, cellFormula);
-        }
-    }
 }
index 8be98c56569b8e5f090ac12615ee6bfe207fd725..94c88219e9b0bc0f0b82ec9391e9eb68734035cf 100644 (file)
@@ -1171,11 +1171,10 @@ public final class FormulaParser {
             while(!done) {
                 sb.appendCodePoint(look);
                 GetChar();
-                switch (look){
-                    case '\'' :
-                        GetChar();
-                    case ':' :
-                        done = true;
+                if(look == '\'')
+                {
+                    Match('\'');
+                    done = look != '\'';
                 }
             }
 
@@ -1201,9 +1200,6 @@ public final class FormulaParser {
                 sb.appendCodePoint(look);
                 GetChar();
             }
-            if (look == '\'') {
-                GetChar();
-            }
             NameIdentifier iden = new NameIdentifier(sb.toString(), false);
             SkipWhite();
             if (look == '!') {
@@ -1253,7 +1249,6 @@ public final class FormulaParser {
         switch(ch) {
             case '.': // dot is OK
             case '_': // underscore is OK
-            case ' ': // space is OK
                 return true;
         }
         return false;
index 2a90ae6f442b8af2bd1dd2db38d6bd8caf6dc05e..3a35909cc2487234e1e2c1b601eabf6c486216da 100644 (file)
@@ -44,16 +44,7 @@ final class ExternSheetNameResolver {
                 ExternalSheetRange r = (ExternalSheetRange)externalSheet;
                 if (! r.getFirstSheetName().equals(r.getLastSheetName())) {
                     sb.append(':');
-                    // quote should appear at the beginning and end.
-                    StringBuilder innerBuilder = new StringBuilder();
-                    SheetNameFormatter.appendFormat(innerBuilder, r.getLastSheetName());
-                    char quote = '\'';
-                    if (innerBuilder.charAt(0) == quote){
-                        sb.insert(0 , quote);
-                        sb.append(innerBuilder.substring(1));
-                    } else {
-                        sb.append(innerBuilder);
-                    }
+                    SheetNameFormatter.appendFormat(sb, r.getLastSheetName());
                 }
             }
         } else {
index 0768cd713ef0e70530e496a366f1c4006d5ec675..6c55d18224f3d335864b52f97b89521028a29c86 100644 (file)
@@ -535,9 +535,9 @@ final class TestFormulaParser {
         assertEquals("'Test Sheet'!A1", formula);
 
         // Now both
-        cell.setCellFormula("'Cash_Flow:Test Sheet'!A1");
+        cell.setCellFormula("Cash_Flow:'Test Sheet'!A1");
         formula = cell.getCellFormula();
-        assertEquals("'Cash_Flow:Test Sheet'!A1", formula);
+        assertEquals("Cash_Flow:'Test Sheet'!A1", formula);
 
 
         // References to a range (area) of cells:
@@ -553,9 +553,9 @@ final class TestFormulaParser {
         assertEquals("'Test Sheet'!A1:B2", formula);
 
         // Now both
-        cell.setCellFormula("'Cash_Flow:Test Sheet'!A1:B2");
+        cell.setCellFormula("Cash_Flow:'Test Sheet'!A1:B2");
         formula = cell.getCellFormula();
-        assertEquals("'Cash_Flow:Test Sheet'!A1:B2", formula);
+        assertEquals("Cash_Flow:'Test Sheet'!A1:B2", formula);
 
         wb.close();
     }
index 1c952d2a602a6ae7fb10aa2d677afbbda1f7914e..eba86eadf39dc5d1c14d0f46fd91bb4c4b545147 100644 (file)
@@ -499,11 +499,11 @@ public abstract class BaseTestWorkbook {
 
 
     /**
-     * Test to validate that replacement for removed setRepeatingRowsAnsColumns() methods
+     * Test to validate that replacement for removed setRepeatingRowsAndColumns() methods
      * is still working correctly
      */
     @Test
-    void setRepeatingRowsAnsColumns() throws IOException {
+    void setRepeatingRowsAndColumns() throws IOException {
         try (Workbook wb = _testDataProvider.createWorkbook()) {
             CellRangeAddress cra = new CellRangeAddress(0, 3, 0, 0);
             String expRows = "1:4", expCols = "A:A";