]> source.dussan.org Git - poi.git/commitdiff
Fix bug #56278 - Support loading .xlsx files with no Styles Table
authorNick Burch <nick@apache.org>
Mon, 17 Mar 2014 19:02:21 +0000 (19:02 +0000)
committerNick Burch <nick@apache.org>
Mon, 17 Mar 2014 19:02:21 +0000 (19:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1578518 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/56278.xlsx [new file with mode: 0644]

index 5018c71ea394c9f6b7df6ff4fc771b4bb69508c5..2955300e42a52ba6de757f563bf629a40672b002 100644 (file)
@@ -295,10 +295,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
                     shIdMap.put(p.getPackageRelationship().getId(), (XSSFSheet)p);
                 }
             }
+            
+            if (stylesSource == null) {
+                // Create Styles if it is missing
+                stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
+            }
             stylesSource.setTheme(theme);
 
             if(sharedStringSource == null) {
-                //Create SST if it is missing
+                // Create SST if it is missing
                 sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
             }
 
index 3c24acc7fd96d2fcf70b97e99b45f27f905f9b6a..e456992a5e892f2f8fe9877b04d87bee30043617 100644 (file)
@@ -1440,4 +1440,19 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
         assertEquals("#@_#", c.getStringCellValue()); 
         assertEquals("http://invalid.uri", c.getHyperlink().getAddress()); 
     }
+    
+    /**
+     * Was giving NullPointerException
+     * at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead
+     * due to a lack of Styles Table
+     */
+    @Test
+    public void bug56278() throws Exception {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56278.xlsx");
+        assertEquals(0, wb.getSheetIndex("Market Rates"));
+        
+        // Save and re-check
+        Workbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertEquals(0, nwb.getSheetIndex("Market Rates"));
+    }
 }
diff --git a/test-data/spreadsheet/56278.xlsx b/test-data/spreadsheet/56278.xlsx
new file mode 100644 (file)
index 0000000..f710851
Binary files /dev/null and b/test-data/spreadsheet/56278.xlsx differ