]> source.dussan.org Git - poi.git/commitdiff
Fix bug #51963 - Correct AreaReference handling of references containing a sheet...
authorNick Burch <nick@apache.org>
Wed, 5 Oct 2011 21:18:25 +0000 (21:18 +0000)
committerNick Burch <nick@apache.org>
Wed, 5 Oct 2011 21:18:25 +0000 (21:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1179444 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/ss/util/AreaReference.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/51963.xlsx [new file with mode: 0644]

index 219eb309324cb97a6b5ea4b164bb91abfd404296..cb49fb56ab28fcd4d535fa57a625709cda35d138 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51963 - Correct AreaReference handling of references containing a sheet name which includes a comma</action>
            <action dev="poi-developers" type="fix">51955 - XSSFReader supplied StylesTables need to have the theme data available</action>
            <action dev="poi-developers" type="fix">51716 - Removed incorrect assert in SXSSFSheet#getSXSSFSheet</action>
            <action dev="poi-developers" type="fix">51834 - Opening and Writing .doc file results in corrupt document</action>
index ffa0c8888d041e0f6433abe9e02f529cddb80d8f..2082634d18160ec843c6e50f17138512f301db6a 100644 (file)
@@ -152,13 +152,20 @@ public class AreaReference {
      *  unbroken) area, or is it made up of
      *  several different parts?
      * (If it is, you will need to call
-     *  ....
+     *  {@link #generateContiguous(String)})
      */
     public static boolean isContiguous(String reference) {
-        if(reference.indexOf(',') == -1) {
-            return true;
-        }
-        return false;
+       // If there's a sheet name, strip it off
+       int sheetRefEnd = reference.indexOf('!'); 
+       if(sheetRefEnd != -1) {
+          reference = reference.substring(sheetRefEnd);
+       }
+
+       // Check for the , as a sign of non-coniguous
+       if(reference.indexOf(',') == -1) {
+          return true;
+       }
+       return false;
     }
 
     public static AreaReference getWholeRow(String start, String end) {
index dd62f7d66804c6de8da3cc24b551d76a0f13af2d..4467dc46a4e115add28de058d888fc7060de76f8 100644 (file)
@@ -43,6 +43,7 @@ import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.AreaReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.CalculationChain;
@@ -1230,4 +1231,22 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
        assertNotNull(sh1.getCommentsTable(false));
        assertEquals(2, sh1.getCommentsTable(false).getNumberOfComments());
     }
+    
+    /**
+     * Sheet names with a , in them
+     */
+    public void test51963() throws Exception {
+       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51963.xlsx");
+       XSSFSheet sheet = wb.getSheetAt(0);
+       assertEquals("Abc,1", sheet.getSheetName());
+       
+       Name name = wb.getName("Intekon.ProdCodes");
+       assertEquals("'Abc,1'!$A$1:$A$2", name.getRefersToFormula());
+       
+       AreaReference ref = new AreaReference(name.getRefersToFormula());
+       assertEquals(0, ref.getFirstCell().getRow());
+       assertEquals(0, ref.getFirstCell().getCol());
+       assertEquals(1, ref.getLastCell().getRow());
+       assertEquals(0, ref.getLastCell().getCol());
+    }
 }
diff --git a/test-data/spreadsheet/51963.xlsx b/test-data/spreadsheet/51963.xlsx
new file mode 100644 (file)
index 0000000..154c754
Binary files /dev/null and b/test-data/spreadsheet/51963.xlsx differ