Created attachment 22906 [details] Excel with cloned sheet and image error The Methode cloneSheet of the HSSFWorkbook-Object is not working well. If there are images in the original Sheet, the cloned Sheet has not a copy of this image. There is a placeholder for this image place (red cross: The picture cannot be displayed) but nothing else. Example: HSSFWorkbook wb = new HSSFWorkbook(this.getClass().getClassLoader().getResourceAsStream("myfile.xls")); wb.cloneSheet(0);
The bug is pretty easy to reproduce. It seems like the solution may involve updating of some drawing IDs in the newly cloned records. Another bug which may need to get fixed here is that BiffViewer crashes when the embedded image is bigger than one BIFF record.
I'm looking at the source code in 3.5, and notice a cut-n-paste error which might be generating this issue (both of thse issues?): In DrawingRecord.java, at the bottom, in the clone() function, the block: if (contd != null) { System.arraycopy(contd, 0, rec.contd, 0, contd.length); rec.contd = new byte[ contd.length ]; } should be: if (contd != null) { rec.contd = new byte[ contd.length ]; System.arraycopy(contd, 0, rec.contd, 0, contd.length); } The former would cause null pointer exceptions and broken drawing references in cloned workbooks/sheets, wouldn't it?
Did you find a solution to this problem? We encounter the same issue since we migrated our environements on Excel 2007 (before we were on Excel 2003). On the original sheet, the image shows up correctly but on the cloned sheets there is a red cross instead.
This bug still exists in 3.7 and 3.8b - when you clone a sheet that has an image in it, it will copy it once. If you clone the sheet again or clone the cloned sheet the image does not appear and instead the X with error message previously reported by many does appear. Would be great if this could be fixed for the 3.8 release if anyone knows what is going on here! Thanks Matt
Should be fixed in r1148295 Please try with the latest build from trunk. Daily builds can be downloaded from here: http://encore.torchbox.com/poi-cvs-build/ Yegor
I just pulled poi-3.8-beta4-20110719.jar and reinitiated my classes and tried again and the first two cloned sheets have the original image in it, the next sheets have the error still.
I committed the fix today and you've tried the yesterday's build. Try tomorrow or checkout from svn and build yourself. Yegor
I just tested with nightly jar from poi-3.8-beta4-20110722.jar and IT IS WORKING - woo hoo! Thank you so much for the fix. I am sure others will be happy as i see posts in various places about this issue. I just did 175 clones of a master template worksheet and the image is in every one!!! Thanks Matt
poi-3.8-beta4-20110722 was working but the feature is broken once again somehow in the new release candidate today poi-bin-3.8-beta4-20110822. Hopefully this fix can get integrated into the final 3.8 beta 4 Thanks Matt
(In reply to comment #9) > poi-3.8-beta4-20110722 was working but the feature is broken once again somehow > in the new release candidate today poi-bin-3.8-beta4-20110822. > Under what circumstances? Cloning sheets with images is working fine to me, I've just checked against the attached file and a new file created in MS Office 2010. If you are able top reproduce the bug, please attach the input file and Java code that we can use for testing. Yegor
I apologize but this bug is still fixed in the beta4 release candidate (20110822) it was still broken in 3.7 which was accidentally in my class path.
Clonesheet is currently working with 3.8 final with an image in the original sheet being cloned. When i installed the 3.9 build from 09/07/2012 (and one about a month ago) I am now getting an error when calling the cloneSheet function... we use coldfusion and here is the stacktrace: java.lang.NullPointerException at org.apache.poi.hssf.usermodel.HSSFTextbox.cloneShape(HSSFTextbox.java:234) at org.apache.poi.hssf.usermodel.HSSFPatriarch.createPatriarch(HSSFPatriarch.java:88) at org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:132) at org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:682) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at coldfusion.runtime.StructBean.invoke(StructBean.java:508) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2393) at Thanks Matt
Hi, Can you please produce a unit test that shows the problem and source xls file you try to clone(if you use existing one)? Regards, Evgeniy (In reply to comment #12) > Clonesheet is currently working with 3.8 final with an image in the original > sheet being cloned. When i installed the 3.9 build from 09/07/2012 (and one > about a month ago) I am now getting an error when calling the cloneSheet > function... > > we use coldfusion and here is the stacktrace: > > java.lang.NullPointerException at > org.apache.poi.hssf.usermodel.HSSFTextbox.cloneShape(HSSFTextbox.java:234) > at > org.apache.poi.hssf.usermodel.HSSFPatriarch.createPatriarch(HSSFPatriarch. > java:88) at > org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet(HSSFSheet.java:132) at > org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet(HSSFWorkbook.java:682) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: > 39) at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl. > java:25) at java.lang.reflect.Method.invoke(Method.java:597) at > coldfusion.runtime.StructBean.invoke(StructBean.java:508) at > coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2393) at > > > Thanks > Matt
This problem should be fixed in trunk. Please try with a nightly build - see download links on http://poi.apache.org/ or build yourself from SVN trunk, see http://poi.apache.org/subversion.html Regards, Evgeniy