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