From 9a492d227eaff4d44699dc1061f3600aa3c678f5 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 15 Dec 2009 09:30:30 +0000 Subject: [PATCH] preserve POIFS StorageClsid when re-writing existing workbooks, this property is important for embedded objects, see Bugzilla 47920 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@890714 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/HSSFWorkbook.java | 8 ++++-- .../poi/hssf/usermodel/TestHSSFWorkbook.java | 24 +++++++++++++++--- test-data/spreadsheet/47920.xls | Bin 0 -> 20480 bytes 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 test-data/spreadsheet/47920.xls diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index a935916bad..ca10a6f874 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -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); } /** diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index ab7cca3186..39a911c53e 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -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 index 0000000000000000000000000000000000000000..c01eabf85bfeac24bec028c84f1592a90fc2caab GIT binary patch literal 20480 zcmeHP349bqy6>4JWH=O1MDTzi+*inf94inGL0JL_!Xj&22+4#5LV_U}P*{R4D#9Xy z2n*p7!WjYt@gt+}DlKoYOPz1A9TCJ1i0r?^_P*-X(cAl&}<_&2hE z39?f8{rC9Kw7_^F5`WQxUKlP!;2I^&r>b1ong>&oiz zocKSi{!M`r+lxb4^OF45zJThdJHk3pLr^17V^9;&BcMk?lmgW7>SKzKNtR?f?UbU9`_cFZDAj}cG z*dG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