poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r615206 - in /poi/branches/ooxml: build.xml src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Date Fri, 25 Jan 2008 12:34:34 GMT
Author: ugo
Date: Fri Jan 25 04:34:33 2008
New Revision: 615206

URL: http://svn.apache.org/viewvc?rev=615206&view=rev
Log:
Use new version of OpenXML4J that allows saving straight to an OutputStream without going
through a file.

Modified:
    poi/branches/ooxml/build.xml
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java

Modified: poi/branches/ooxml/build.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/build.xml?rev=615206&r1=615205&r2=615206&view=diff
==============================================================================
--- poi/branches/ooxml/build.xml (original)
+++ poi/branches/ooxml/build.xml Fri Jan 25 04:34:33 2008
@@ -145,8 +145,8 @@
   <property name="ooxml.jar4.dir" location="${ooxml.lib}/jsr173_1.0_api.jar"/>
   <property name="ooxml.jar4.url" value="${repository}/xmlbeans/jars/jsr173_1.0_api.jar"/>
   <!-- No official release of openxml4j yet -->
-  <property name="ooxml.jar5.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080124.jar"/>
-  <property name="ooxml.jar5.url" value="http://people.apache.org/~nick/openxml4j-bin-prealpha-071224.jar"/>
+  <property name="ooxml.jar5.dir" location="${ooxml.lib}/openxml4j-bin-alpha-080125.jar"/>
+  <property name="ooxml.jar5.url" value="http://people.apache.org/~ugo/openxml4j-bin-alpha-080125.jar"/>
 
   <!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
   <!-- "Copy these file(s), free of charge" -->

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=615206&r1=615205&r2=615206&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 Fri
Jan 25 04:34:33 2008
@@ -17,9 +17,6 @@
 
 package org.apache.poi.xssf.usermodel;
 
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.LinkedList;
@@ -364,20 +361,11 @@
 
     }
 
-    /**
-     * XXX: Horribly naive implementation based on OpenXML4J's Package class,
-     * which sucks because it does not allow instantiation using an
-     * OutputStream instead of a File. So we write the Package to a temporary
-     * file, which we then proceed to read and stream out.
-     */
     public void write(OutputStream stream) throws IOException {
-        // Create a temporary file
-        File file = File.createTempFile("poi-", ".xlsx");
-        file.delete();
 
         try {
             // Create a package referring the temp file.
-            Package pkg = Package.create(file);
+            Package pkg = Package.create(stream);
             // Main part
             PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
             // Create main part relationship
@@ -397,7 +385,7 @@
              workbook.save(out, xmlOptions);
              out.close();
              
-             for (int i = 1 ; i <= this.getNumberOfSheets() ; ++i) {
+             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);
@@ -409,23 +397,11 @@
                  out = part.getOutputStream();
                  sheet.getWorksheet().save(out, xmlOptions);
                  
-                 // XXX DEBUG
-                 System.err.println(sheet.getWorksheet().xmlText(xmlOptions));
                  out.close();
              }
              
              pkg.close();
              
-             byte[] buf = new byte[8192];
-             int nread = 0;
-             BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
-             try {
-                 while ((nread = bis.read(buf)) > 0) {
-                     stream.write(buf, 0, nread);
-                 }
-             } finally {
-                 bis.close();
-             }
         } catch (InvalidFormatException e) {
             // TODO: replace with more meaningful exception
             throw new RuntimeException(e);

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=615206&r1=615205&r2=615206&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Fri Jan 25 04:34:33 2008
@@ -17,6 +17,10 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
 import junit.framework.TestCase;
 
 import org.apache.poi.ss.usermodel.Sheet;
@@ -113,5 +117,17 @@
         assertEquals("sheet3", workbook.getSheetName(0));
         workbook.removeSheetAt(0);
         assertEquals(0, workbook.getNumberOfSheets());
+    }
+    
+    public void testSave() throws Exception {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        Sheet sheet1 = workbook.createSheet("sheet1");
+        Sheet sheet2 = workbook.createSheet("sheet2");
+        Sheet sheet3 = workbook.createSheet("sheet3");
+        File file = File.createTempFile("poi-", ".xlsx");
+        System.out.println("Saving to " + file.getAbsolutePath());
+        OutputStream out = new FileOutputStream(file);
+        workbook.write(out);
+        out.close();
     }
 }



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


Mime
View raw message