]> source.dussan.org Git - poi.git/commitdiff
Fixed XSSFWorkbook#setRepeatingRowsAndColumns to tolerate sheet names with quotes...
authorYegor Kozlov <yegor@apache.org>
Wed, 10 Jun 2009 18:44:53 +0000 (18:44 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 10 Jun 2009 18:44:53 +0000 (18:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@783445 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

index 5438a697044991e13943e1d491646ef689d9de49..cdc47602eba034f3a91bf7b7edc81c174c3b1e5e 100644 (file)
@@ -35,6 +35,7 @@
         <release version="3.5-beta7" date="2009-??-??">
         </release>
         <release version="3.5-beta6" date="2009-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">47294 - Fixed XSSFWorkbook#setRepeatingRowsAndColumns to tolerate sheet names with quotes</action>
            <action dev="POI-DEVELOPERS" type="fix">47309 - Fixed logic in HSSFCell.getCellComment to handle sheets with more than 65536 comments</action>
            <action dev="POI-DEVELOPERS" type="fix">46776 - Added clone() method to MulBlankRecord to fix crash in Sheet.cloneSheet()</action>
            <action dev="POI-DEVELOPERS" type="fix">47244 - Fixed HSSFSheet to handle missing header / footer records</action>
index c288354898d7a69817986c43593f1e2521217641..461fe603940986d90ed8e2c860dd515cdbc89fcf 100644 (file)
@@ -944,7 +944,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
         CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
 
-        String c = "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
+        String escapedName = SheetNameFormatter.format(sheetName);
+
+        String c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
 
         CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
         CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
@@ -952,7 +954,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         String r = "";
 
         if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
-            r = ",'" + sheetName + "'!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
+            r = "," + escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
         }
         return c + r;
     }
index c1e66431e31bb5a50bfb5c6c9597bda3be7cc375..14bfdc790b68ffc91e3cd193d95cf781e6009034 100755 (executable)
@@ -37,7 +37,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
         // First test that setting RR&C for same sheet more than once only creates a
         // single  Print_Titles built-in record
         XSSFWorkbook wb = getTestDataProvider().createWorkbook();
-        XSSFSheet sheet = wb.createSheet("FirstSheet");
+        XSSFSheet sheet = wb.createSheet("First Sheet");
 
         // set repeating rows and columns twice for the first sheet
         for (int i = 0; i < 2; i++) {
@@ -48,7 +48,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
         XSSFName nr1 = wb.getNameAt(0);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-        assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+        assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
 
         // Save and re-open
         XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -57,7 +57,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
         nr1 = nwb.getNameAt(0);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-        assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+        assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
 
         // check that setting RR&C on a second sheet causes a new Print_Titles built-in
         // name to be created
@@ -68,7 +68,7 @@ public final class TestXSSFName extends BaseTestNamedRange {
         XSSFName nr2 = nwb.getNameAt(1);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
-        assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
+        assertEquals("SecondSheet!$B:$C,SecondSheet!$1:$1", nr2.getRefersToFormula());
 
         nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
     }
index 4e5c71f2faab8091175f3b64005bdc2de59c4481..1c99f967485ab809d50546da2d09b6ec2b2ad6b0 100755 (executable)
@@ -293,6 +293,16 @@ public abstract class BaseTestWorkbook extends TestCase {
         assertSame(row, cell.getRow());
     }
 
+    public void testSetRepeatingRowsAnsColumns(){
+        Workbook wb = getTestDataProvider().createWorkbook();
+        Sheet sheet1 = wb.createSheet();
+        wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3);
+
+        //must handle sheets with quotas, see Bugzilla #47294
+        Sheet sheet2 = wb.createSheet("My' Sheet");
+        wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet2), 0, 0, 0, 3);
+    }
+
     /**
      * Tests that all of the unicode capable string fields can be set, written and then read back
      */