]> source.dussan.org Git - poi.git/commitdiff
preserve POIFS StorageClsid when re-writing existing workbooks, this property is...
authorYegor Kozlov <yegor@apache.org>
Tue, 15 Dec 2009 09:30:30 +0000 (09:30 +0000)
committerYegor Kozlov <yegor@apache.org>
Tue, 15 Dec 2009 09:30:30 +0000 (09:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@890714 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
test-data/spreadsheet/47920.xls [new file with mode: 0644]

index a935916bad2517e65e20deed6087f9bde9b9ca35..ca10a6f8743e2c1ecfeb671895604c9cb31b2e43 100644 (file)
@@ -1175,11 +1175,15 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
             //  out correctly shortly, so don't include the old one
             excepts.add("WORKBOOK");
 
+            POIFSFileSystem srcFs = this.filesystem;
             // Copy over all the other nodes to our new poifs
-            copyNodes(this.filesystem,fs,excepts);
+            copyNodes(srcFs, fs, excepts);
+
+            // YK: preserve StorageClsid, it is important for embedded workbooks,
+            // see Bugzilla 47920
+            fs.getRoot().setStorageClsid(srcFs.getRoot().getStorageClsid());
         }
         fs.writeFilesystem(stream);
-        //poifs.writeFilesystem(stream);
     }
 
     /**
index ab7cca318683523cb7260917ba2195cf73b3ef44..39a911c53ed0d137bc2d3ff40b251cbcaefe1adf 100644 (file)
@@ -17,9 +17,7 @@
 
 package org.apache.poi.hssf.usermodel;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.util.List;
 
 import junit.framework.AssertionFailedError;
@@ -37,6 +35,9 @@ import org.apache.poi.hssf.record.formula.Area3DPtg;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.TempFile;
 import org.apache.poi.ss.usermodel.BaseTestWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hpsf.ClassID;
 
 /**
  * Tests for {@link HSSFWorkbook}
@@ -505,4 +506,21 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
         nr = wb.getWorkbook().getNameRecord(2);
         assertEquals("Sheet2!E:F,Sheet2!$A$9:$IV$12", HSSFFormulaParser.toFormulaString(wb, nr.getNameDefinition())); // E:F,9:12
     }
+
+    /**
+     * Test that the storage clsid property is preserved
+     */
+    public void test47920() throws IOException {
+        POIFSFileSystem fs1 = new POIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("47920.xls"));
+        HSSFWorkbook wb = new HSSFWorkbook(fs1);
+        ClassID clsid1 = fs1.getRoot().getStorageClsid();
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
+        wb.write(out);
+        byte[] bytes = out.toByteArray();
+        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(bytes));
+        ClassID clsid2 = fs2.getRoot().getStorageClsid();
+
+        assertTrue(clsid1.equals(clsid2));
+    }
 }
diff --git a/test-data/spreadsheet/47920.xls b/test-data/spreadsheet/47920.xls
new file mode 100644 (file)
index 0000000..c01eabf
Binary files /dev/null and b/test-data/spreadsheet/47920.xls differ