]> source.dussan.org Git - poi.git/commitdiff
Moved test data file to own package.\rStart writing some tests for parsing cell styles.
authorUgo Cei <ugo@apache.org>
Tue, 19 Feb 2008 12:56:51 +0000 (12:56 +0000)
committerUgo Cei <ugo@apache.org>
Tue, 19 Feb 2008 12:56:51 +0000 (12:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@629092 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/log4j.properties [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/data/styles.xlsx [new file with mode: 0644]
src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java
src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx [deleted file]

index 309225b3a655cebbb290587b2ccf18f74788abc5..4d261a4b315cf1f2d8684f12a075aa13515ec1c5 100644 (file)
@@ -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<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
     
     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 (file)
index 0000000..8479c8d
--- /dev/null
@@ -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/data/sample.xlsx b/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx
new file mode 100644 (file)
index 0000000..a275cf4
Binary files /dev/null and b/src/ooxml/testcases/org/apache/poi/xssf/data/sample.xlsx differ
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 (file)
index 0000000..dbfa53c
Binary files /dev/null and b/src/ooxml/testcases/org/apache/poi/xssf/data/styles.xlsx differ
index 1c445f2b07c652f5d41e985ab618d468dce3a715..ec2b113b86dd8ab038dae0ecccb1009c58ae6764 100644 (file)
@@ -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);
+    }
 
 }
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx b/src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx
deleted file mode 100644 (file)
index a275cf4..0000000
Binary files a/src/ooxml/testcases/org/apache/poi/xssf/io/sample.xlsx and /dev/null differ