Bug 52268 - Missing images on cloned sheets.
Summary: Missing images on cloned sheets.
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.7-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-01 10:01 UTC by Michael
Modified: 2011-12-07 08:52 UTC (History)
1 user (show)



Attachments
Patch that solves problem with cloning sheet with images (3.47 KB, patch)
2011-12-01 10:01 UTC, Michael
Details | Diff
Sample input file that produce bug (151.69 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2011-12-01 10:02 UTC, Michael
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2011-12-01 10:01:18 UTC
Created attachment 28009 [details]
Patch that solves problem with cloning sheet with images

TC
Create "in.xlsx" file with sheet that contents images.
Try to clone that sheet.

Code:
is = new BufferedInputStream(new FileInputStream(WORKING_DIR + "in.xlsx"));
os = new BufferedOutputStream(new FileOutputStream(WORKING_DIR + "out.xlsx"));
Workbook workbook = WorkbookFactory.create(is);

workbook.cloneSheet(0);

workbook.write(os);

Open out.xlsx with Microsoft Office.

ER
There will be images on the cloned sheet.

AR
There are no images on the cloned sheet.


I found the problem that cause this bug and made patch that solve that problem (see the attachment).
Comment 1 Michael 2011-12-01 10:02:28 UTC
Created attachment 28010 [details]
Sample input file that produce bug
Comment 2 Nick Burch 2011-12-01 11:23:18 UTC
Is it possible to write a unit test to check for the correct cloning?

Ideally we'd want to do the check using a unit test, so we can automatically make sure it doesn't get broken in future. Checks which require loading into Excel tend not to get done very often, so it's generally safer to unit test it where possible!
Comment 3 Michael 2011-12-01 12:03:35 UTC
I could not find public api that get information about images on sheet. The only way is to comparison of sheet.xml, sheet.xml.rels, drawing.xml and drawing.xml.rels files by xmlbeans, but I think it is not good way for unit-tests.

May be in the future there will be frendly api for working with images on sheet, it would be possible to make good unit-tests.
Comment 4 Yegor Kozlov 2011-12-05 07:17:14 UTC
The patch looks OK, but I'm reluctant to apply it without a unit test. You are right - current implementation of XSSFDrawing  can't iterate over shapes, but this functionality should be easy to add. I recall that last time I was trying to do that I couldn't properly parse CTDrawing - it had something to do with XmlBeans and extra root element. 

Now I see that passing XmlOpetions with

options.setLoadReplaceDocumentElement(null); 

does the trick. Thanks for finding it! 

I plan to commit the patch in a few days.

Regards,
Yegor
Comment 5 Yegor Kozlov 2011-12-07 08:52:58 UTC
Applied in r1211339 with some tweaks, junit added.

Regards,
Yegor