diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 309225b3a6..4d261a4b31 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -34,6 +34,8 @@ import org.apache.poi.ss.usermodel.Palette; import org.apache.poi.ss.usermodel.SharedStringSource; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.xssf.strings.SharedStringsTable; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; @@ -69,6 +71,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { private List sheets = new LinkedList(); private SharedStringSource sharedStringSource; + + private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class); public XSSFWorkbook() { this.workbook = CTWorkbook.Factory.newInstance(); @@ -94,6 +98,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { // Load individual sheets for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) { PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId()); + if (rel == null) { + log.log(log.WARN, "No relationship found for sheet " + ctSheet.getId()); + continue; + } PackagePart part = getPart(rel); WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream()); XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet(), this); diff --git a/src/ooxml/testcases/log4j.properties b/src/ooxml/testcases/log4j.properties new file mode 100644 index 0000000000..8479c8de26 --- /dev/null +++ b/src/ooxml/testcases/log4j.properties @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +log4j.debug=false + +log4j.rootLogger=INFO,Stdout + +log4j.appender.Stdout=org.apache.log4j.ConsoleAppender +log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n + +log4j.org.apache.poi=DEBUG \ No newline at end of file diff --git a/src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx b/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx similarity index 100% rename from src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx rename to src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx diff --git a/src/ooxml/testcases/org/apache/poi/xssf/data/styles.xlsx b/src/ooxml/testcases/org/apache/poi/xssf/data/styles.xlsx new file mode 100644 index 0000000000..dbfa53cfbf Binary files /dev/null and b/src/ooxml/testcases/org/apache/poi/xssf/data/styles.xlsx differ diff --git a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java index 1c445f2b07..ec2b113b86 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java @@ -22,6 +22,7 @@ import java.io.File; import junit.framework.TestCase; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; @@ -33,9 +34,10 @@ public class TestLoadSaveXSSF extends TestCase { protected void setUp() throws Exception { super.setUp(); + System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName()); filename = System.getProperty("HSSF.testdata.path"); if (filename == null) { - filename = "src/testcases/org/apache/poi/hssf/data"; + filename = "src/ooxml/testcases/org/apache/poi/xssf/data"; } } @@ -51,5 +53,14 @@ public class TestLoadSaveXSSF extends TestCase { cell = row.getCell((short) 0); assertEquals("Lorem", cell.getRichStringCellValue().getString()); } + + public void testLoadStyles() throws Exception { + XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "styles.xlsx").getAbsolutePath()); + Sheet sheet = workbook.getSheetAt(0); + Row row = sheet.getRow(0); + Cell cell = row.getCell((short) 0); + CellStyle style = cell.getCellStyle(); + // assertNotNull(style); + } }