]> source.dussan.org Git - poi.git/commitdiff
Fix bug #49702 - Correct XSSFWorkbook.getNumCellStyles to check the right styles...
authorNick Burch <nick@apache.org>
Wed, 4 Aug 2010 14:40:54 +0000 (14:40 +0000)
committerNick Burch <nick@apache.org>
Wed, 4 Aug 2010 14:40:54 +0000 (14:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@982269 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

index effa0239f0e2f00cbf3f33149b60840fc74e759b..d5e39d391866061ea8c214e47328dff4e1441f6d 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49702 - Correct XSSFWorkbook.getNumCellStyles to check the right styles list</action>
            <action dev="POI-DEVELOPERS" type="add">49690 - Add WorkbookUtil, which provies a way of generating valid sheet names</action>
            <action dev="POI-DEVELOPERS" type="fix">49694 - Use DataFormatter when autosizing columns, to better match the real display width of formatted cells</action>
            <action dev="POI-DEVELOPERS" type="add">49441 - Allow overriding and guessing of HSMF non-unicode string encodings</action>
index 98c3c5f18d73e75f2d81d6cd984b57842027cb7e..0230d660fdcd270491d51392dd6d77e81e3f6256 100644 (file)
@@ -280,7 +280,9 @@ public class StylesTable extends POIXMLDocumentPart {
         * get the size of cell styles
         */
        public int getNumCellStyles(){
-               return styleXfs.size();
+        // Each cell style has a unique xfs entry
+        // Several might share the same styleXfs entry
+        return xfs.size();
        }
 
        /**
index 5ec6257d7c7a87b105ab9ed81eaee85e9e143631..473b1892395b03ec841f081ee7782fa7c8e0428a 100644 (file)
@@ -271,7 +271,7 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
         * Verify that the attached test data was not modified. If this test method
         * fails, the test data is not working properly.
         */
-       public void test47668() throws Exception {
+       public void testBug47668() throws Exception {
                XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("47668.xlsx");
                List<XSSFPictureData> allPictures = workbook.getAllPictures();
                assertEquals(2, allPictures.size());
@@ -354,4 +354,55 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook {
                assertEquals("Numbers", wb.getSheetName(0));
                assertEquals("Chart", wb.getSheetName(1));
        }
+       
+       /**
+        * Problems with the count of the number of styles
+        *  coming out wrong
+        */
+       public void testBug49702() throws Exception {
+           // First try with a new file
+           XSSFWorkbook wb = new XSSFWorkbook();
+
+           // Should have one style
+           assertEquals(1, wb.getNumCellStyles());
+           wb.getCellStyleAt((short)0);
+           try {
+               wb.getCellStyleAt((short)1);
+               fail("Shouldn't be able to get style at 1 that doesn't exist");
+           } catch(IndexOutOfBoundsException e) {}
+
+           // Add another one
+           CellStyle cs = wb.createCellStyle();
+           cs.setDataFormat((short)11);
+
+           // Re-check
+           assertEquals(2, wb.getNumCellStyles());
+           wb.getCellStyleAt((short)0);
+           wb.getCellStyleAt((short)1);
+           try {
+               wb.getCellStyleAt((short)2);
+               fail("Shouldn't be able to get style at 2 that doesn't exist");
+           } catch(IndexOutOfBoundsException e) {}
+
+           // Save and reload
+           XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+           assertEquals(2, nwb.getNumCellStyles());
+           nwb.getCellStyleAt((short)0);
+           nwb.getCellStyleAt((short)1);
+           try {
+               nwb.getCellStyleAt((short)2);
+               fail("Shouldn't be able to get style at 2 that doesn't exist");
+           } catch(IndexOutOfBoundsException e) {}
+
+           // Now with an existing file
+           wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
+           assertEquals(3, wb.getNumCellStyles());
+           wb.getCellStyleAt((short)0);
+           wb.getCellStyleAt((short)1);
+           wb.getCellStyleAt((short)2);
+           try {
+               wb.getCellStyleAt((short)3);
+               fail("Shouldn't be able to get style at 3 that doesn't exist");
+           } catch(IndexOutOfBoundsException e) {}
+       }
 }