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).
Created attachment 28010 [details] Sample input file that produce bug
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!
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.
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
Applied in r1211339 with some tweaks, junit added. Regards, Yegor