You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by andrdk <an...@yahoo.com> on 2009/12/10 14:08:29 UTC

Workarounds/solutions to embed worksheets to Slides using POI

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: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Workarounds/solutions to embed worksheets to Slides using POI

Posted by Roman Kashitsyn <ro...@gmail.com>.
Hi,

I still see the problem with 3.8-beta3-20110505.
The way of reproduction is the following:
1. Create a ppt presentation with PowerPoint 2007 and embed a xls(x) file
into it.
2. Create a workbook with Apache POI.
3. Open ppt presentation with Apache POI and replace corresponding OLEShape
entry with new workbook.

As result I have the following message in PowerPoint 2007 when I try to open
embedded file: "The server
application, source file, or item can't be found, or returned as an
unknown error. You may need to reinstall the server application.".

OpenOffice 3.2.1 opens embedded file perfectly well.

The source code is something like that:

SlideShow ppt = new SlideShow(new HSLFSlideShow(file.getPath()));
Slide[] slides = ppt.getSlides();
Slide slide = slides[0];

for (Shape s : slide.getShapes()) {
	if (s instanceof OLEShape) {
		OLEShape ole = (OLEShape) s;
		ObjectData data = ole.getObjectData();
		data.setData(getWorkbookBytes(workbookInstance));
	}
}

FileOutputStream fos = new FileOutputStream(file);
ppt.write(fos);
fos.close();


Thank you in advance,
Roman

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Workarounds-solutions-to-embed-worksheets-to-Slides-using-POI-tp2300252p4372242.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Workarounds/solutions to embed worksheets to Slides using POI

Posted by Yegor Kozlov <ye...@dinom.ru>.
The problem has been fixed in r890714.

When embedding a workbook, MS Office modifies the .xls file and sets a special
property called StorageClassID. It turned out that this property is important
for embedded objects - MS Office uses it to activate the document's
application. HSSFWorkbook did not preserve this property across read-write and it
was the reason why PowerPoint could not open embedded .xls after modification.

Daily builds can be downloaded from http://encore.torchbox.com/poi-svn-build/

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: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Workarounds/solutions to embed worksheets to Slides using POI

Posted by Yegor Kozlov <ye...@dinom.ru>.
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: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org