I did some research and the problem looks more complicated than just updating embedded data via ExOleObjStg.setData.
HSLF API works correctly, I confirmed that ExOleObjStg record works OK. It is the workbook being embedded that needs to
be modified in order to be opened from the containing presentation.
Compare two code snippets:
(1) read the embedded OLE2 file system and write back. Note, that the workbook
data is not parsed.
Although the number of written bytes is different from the original, I could
open the embedded xls from its container ppt.
OLEShape ole = (OLEShape) shape[j];
ObjectData data = ole.getObjectData();
String name = ole.getInstanceName();
//read xls and re-build the OLE2 file system
POIFSFileSystem fs = new POIFSFileSystem(data.getData());
//write to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
fs.writeFilesystem(out);
//write back to the ppt
data.setData(out.toByteArray());
(2) read the embedded .xls into HSSFWorkbook and write back. In this case the embedded file can not be opened from
within ppt.
OLEShape ole = (OLEShape) shape[j];
ObjectData data = ole.getObjectData();
String name = ole.getInstanceName();
//read xls and write back to the ppt
HSSFWorkbook wb = new HSSFWorkbook (data.getData());
//write workbook to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
wb .write(out);
//write back to the ppt
data.setData(out.toByteArray());
Unfortunately I didn't find a workaround. The PPT and XLS specs don't say much on how embedding works - from the format
point of view everything looks OK, both embedded xls and container ppt are valid and can be separately opened by MS
Office. The only trouble is that the embedded workbook cannot be opened from within ppt.
I will update this post if I find a solution.
My two candidates for further research are:
- SummaryInformation and Document SummaryInformation property sets
- Workbooks stream. When parsing a workbook HSSF can miss or not update
certain records
Yegor
Hi,
I am looking for further information in relevance to the following thread
http://thread.gmane.org/gmane.comp.jakarta.poi.user/13275/focus=13278 (Bug
47920).
Are there any workarounds (with usermodel or even record level APIs) to achieve
embedding workbooks to slides? Could you please provide further information on
whether any implementation of setData in ExOleObjStg alone will fix the issue or
it requires further more changes? Any tip towards proceeding on a feasible
workaround/solution to get this issue would be of great help as the bugfix
doesn't seem to be part of POI 3.6 release.
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]