Bug 52268

Summary: Missing images on cloned sheets.
Product: POI Reporter: Michael <obidin>
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal CC: obidin
Priority: P2    
Version: 3.7-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Attachments: Patch that solves problem with cloning sheet with images
Sample input file that produce bug

Description Michael 2011-12-01 10:01:18 UTC
Created attachment 28009 [details]
Patch that solves problem with cloning sheet with images

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

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



Open out.xlsx with Microsoft Office.

There will be images on the cloned sheet.

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


does the trick. Thanks for finding it! 

I plan to commit the patch in a few days.

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