poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r619419 - in /poi/branches/ooxml/src/ooxml: java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/xssf/io/
Date Thu, 07 Feb 2008 14:08:39 GMT
Author: ugo
Date: Thu Feb  7 06:08:32 2008
New Revision: 619419

URL: http://svn.apache.org/viewvc?rev=619419&view=rev
Log:
Fleshing out reading XSSF.

Modified:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=619419&r1=619418&r2=619419&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Thu Feb
 7 06:08:32 2008
@@ -50,6 +50,7 @@
     
     public XSSFCell(XSSFRow row, CTCell cell) {
         this.cell = cell;
+        // TODO: parse cell.getR() to obtain cellnum
         this.row = row;
     }
 

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=619419&r1=619418&r2=619419&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Thu Feb
 7 06:08:32 2008
@@ -35,10 +35,8 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
@@ -67,11 +65,16 @@
         this.sheet = sheet;
         this.worksheet = CTWorksheet.Factory.newInstance();
         this.worksheet.addNewSheetData();
-        this.rows = new LinkedList<Row>();
-        for (CTRow row : worksheet.getSheetData().getRowArray()) {
-                this.rows.add(new XSSFRow(row));
-        }
-        // XXX ???
+        initRows(worksheet);
+        
+        this.worksheet.addNewHeaderFooter();
+        worksheet.addNewRowBreaks();
+        worksheet.addNewColBreaks();
+        CTSheetPr sheetPr = worksheet.addNewSheetPr();
+        sheetPr.addNewPageSetUpPr();
+        worksheet.addNewPageMargins();
+        
+        // XXX Initial default data, probably useful only for testing. Review and eliminate
if necessary.
         CTSheetViews views = this.worksheet.addNewSheetViews();
         CTSheetView view = views.addNewSheetView();
         view.setWorkbookViewId(0);
@@ -95,12 +98,25 @@
             col.setWidth(13);
             col.setCustomWidth(true);
         }
-        CTHeaderFooter hf = this.worksheet.addNewHeaderFooter();
-        CTPageBreak rowBreaks = worksheet.addNewRowBreaks();
-        CTPageBreak columnBreak = worksheet.addNewColBreaks();
-        CTSheetPr sheetPr = worksheet.addNewSheetPr();
-        CTPageSetUpPr sheetPageSetUpPr = sheetPr.addNewPageSetUpPr();
-        CTPageMargins pageMargins = worksheet.addNewPageMargins();
+
+        initColumns(worksheet);
+    }
+    
+    public XSSFSheet(CTSheet sheet, CTWorksheet worksheet) {
+        this.sheet = sheet;
+        this.worksheet = worksheet;
+        initRows(worksheet);
+        initColumns(worksheet);
+    }
+
+    private void initRows(CTWorksheet worksheet) {
+        this.rows = new LinkedList<Row>();
+        for (CTRow row : worksheet.getSheetData().getRowArray()) {
+            this.rows.add(new XSSFRow(row));
+        }
+    }
+
+    private void initColumns(CTWorksheet worksheet) {
         columnHelper = new ColumnHelper(worksheet);
     }
 

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=619419&r1=619418&r2=619419&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Thu
Feb  7 06:08:32 2008
@@ -39,6 +39,7 @@
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 import org.openxml4j.opc.PackagePartName;
+import org.openxml4j.opc.PackageRelationship;
 import org.openxml4j.opc.PackageRelationshipTypes;
 import org.openxml4j.opc.PackagingURIHelper;
 import org.openxml4j.opc.TargetMode;
@@ -48,10 +49,15 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorksheetDocument;
 
 
 public class XSSFWorkbook extends POIXMLDocument implements Workbook {
 
+    private static final String WORKSHEET_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
+
+    private static final String WORKSHEET_RELATIONSHIP = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet";
+
     private CTWorkbook workbook;
     
     private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
@@ -69,8 +75,25 @@
         try {
             WorkbookDocument doc = WorkbookDocument.Factory.parse(getCorePart().getInputStream());
             this.workbook = doc.getWorkbook();
+            for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
+                PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId());
+                PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
+                PackagePart part = getPackage().getPart(relName);
+                if (part == null) {
+                    throw new IllegalArgumentException("No part found for relationship "
+ rel);
+                }
+                WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream());
+                XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet());
+                this.sheets.add(sheet);
+            }
         } catch (XmlException e) {
             throw new IOException(e.toString());
+        } catch (InvalidFormatException e) {
+            throw new IOException(e.toString());
+/*            
+        } catch (OpenXML4JException e) {
+            throw new IOException(e.toString());
+*/
         }
     }
 
@@ -401,9 +424,8 @@
              for (int i = 0 ; i < this.getNumberOfSheets() ; ++i) {
                  XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
                  PackagePartName partName = PackagingURIHelper.createPartName("/xl/worksheets/sheet"
+ i + ".xml");
-                 corePart.addRelationship(partName, TargetMode.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
"rSheet" + 1);
-                 PackagePart part = pkg.createPart(partName, 
-                         "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
+                 corePart.addRelationship(partName, TargetMode.INTERNAL, WORKSHEET_RELATIONSHIP,
"rSheet" + 1);
+                 PackagePart part = pkg.createPart(partName, WORKSHEET_TYPE);
                  
                  // XXX This should not be needed, but apparently the setSaveOuter call above
does not work in XMLBeans 2.2
                  xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(),
"worksheet"));

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java?rev=619419&r1=619418&r2=619419&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/io/TestLoadSaveXSSF.java Thu
Feb  7 06:08:32 2008
@@ -21,6 +21,9 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 
@@ -31,12 +34,20 @@
     protected void setUp() throws Exception {
         super.setUp();
         filename = System.getProperty("HSSF.testdata.path");
+        if (filename == null) {
+            filename = "src/testcases/org/apache/poi/hssf/data";
+        }
     }
     
     public void testLoadSample() throws Exception {
         XSSFWorkbook workbook = new XSSFWorkbook(new File(filename, "sample.xlsx").getAbsolutePath());
         assertEquals(3, workbook.getNumberOfSheets());
         assertEquals("Sheet1", workbook.getSheetName(0));
+        Sheet sheet = workbook.getSheetAt(0);
+        Row row = sheet.getRow(0);
+        Cell cell = row.getCell((short) 1);
+        // assertNotNull(cell);
+        // assertEquals(111.0, cell.getNumericCellValue());
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message