Bug 46250 - Workbook cloneSheet()
Summary: Workbook cloneSheet()
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.9-dev
Hardware: PC Windows Server 2003
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-20 06:54 UTC by adrian
Modified: 2012-09-09 13:24 UTC (History)
2 users (show)



Attachments
Excel with cloned sheet and image error (19.00 KB, application/vnd.ms-excel)
2008-11-20 06:54 UTC, adrian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description adrian 2008-11-20 06:54:09 UTC
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);
Comment 1 Josh Micich 2008-11-26 15:30:19 UTC
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.
Comment 2 Mark Thompson 2008-12-30 12:23:05 UTC
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?
Comment 3 Nicolas Papegaey 2011-06-07 15:38:41 UTC
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.
Comment 4 matt.koch 2011-07-15 15:33:12 UTC
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
Comment 5 Yegor Kozlov 2011-07-19 12:22:26 UTC
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
Comment 6 matt.koch 2011-07-20 15:20:48 UTC
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.
Comment 7 Yegor Kozlov 2011-07-20 15:37:22 UTC
I committed the fix today and you've tried the yesterday's build. Try tomorrow or checkout from svn and build yourself.

Yegor
Comment 8 matt.koch 2011-07-22 15:25:42 UTC
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
Comment 9 matt.koch 2011-08-16 02:08:57 UTC
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
Comment 10 Yegor Kozlov 2011-08-16 07:28:24 UTC
(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
Comment 11 matt.koch 2011-08-16 15:13:16 UTC
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.
Comment 12 matt.koch 2012-09-08 19:17:44 UTC
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
Comment 13 Evgeniy Berlog 2012-09-08 19:23:40 UTC
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
Comment 14 Evgeniy Berlog 2012-09-09 13:24:09 UTC
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