Moved test data file to own package.

Start writing some tests for parsing cell styles.

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@629092 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ugo Cei 2008-02-19 12:56:51 +00:00
parent 8ec2aaafd6
commit c278230bb6
5 changed files with 44 additions and 1 deletions

View 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.SharedStringSource;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; 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.poi.xssf.strings.SharedStringsTable;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
@ -69,6 +71,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>(); private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
private SharedStringSource sharedStringSource; private SharedStringSource sharedStringSource;
private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
public XSSFWorkbook() { public XSSFWorkbook() {
this.workbook = CTWorkbook.Factory.newInstance(); this.workbook = CTWorkbook.Factory.newInstance();
@ -94,6 +98,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook {
// Load individual sheets // Load individual sheets
for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) { for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId()); 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); PackagePart part = getPart(rel);
WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream()); WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream());
XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet(), this); XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet(), this);

View File

@ -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

View File

@ -22,6 +22,7 @@ import java.io.File;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.ss.usermodel.Cell; 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.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -33,9 +34,10 @@ public class TestLoadSaveXSSF extends TestCase {
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
System.setProperty("org.apache.poi.util.POILogger", org.apache.poi.util.CommonsLogger.class.getName());
filename = System.getProperty("HSSF.testdata.path"); filename = System.getProperty("HSSF.testdata.path");
if (filename == null) { 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); cell = row.getCell((short) 0);
assertEquals("Lorem", cell.getRichStringCellValue().getString()); 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);
}
} }