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
This commit is contained in:
Yegor Kozlov 2009-12-15 09:30:30 +00:00
parent 07d15660b9
commit 9a492d227e
3 changed files with 27 additions and 5 deletions

View 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);
}
/**

View 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));
}
}

Binary file not shown.