When attempting to clone a sheet that had an image on it, I got an Exception saying that DrawingRecord must implement a clone() method. I added this clone() method and the image was copied onto the cloned sheets without any problems. public Object clone() { DrawingRecord rec = new DrawingRecord(); rec.recordData = recordData; return rec; }
We are trying to clone a worksheet that has AutoShapes and Pictures in it. After placing the clone method in the DrawingRecord class, we encountered a different exception as follows: java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification (AbstractList.java:462) at java.util.AbstractList$Itr.next(AbstractList.java:433) at org.apache.poi.hssf.record.ObjRecord.clone(ObjRecord.java:182) at org.apache.poi.hssf.model.Sheet.cloneSheet(Sheet.java(Compiled Code)) at org.apache.poi.hssf.usermodel.HSSFSheet.cloneSheet (HSSFSheet.java:114) at org.apache.poi.hssf.usermodel.HSSFWorkbook.cloneSheet (HSSFWorkbook.java:337) After debugging through it, we found out that this error happens in the ObjectRecord clone method(). We modified the clone method as follows: public Object clone() { ObjRecord rec = new ObjRecord(); rec.subrecords = new ArrayList(); List currObj = this.subrecords; for ( Iterator iterator = currObj.iterator(); iterator.hasNext(); ) { rec.subrecords.add(( (Record) iterator.next() ).clone()); } return rec; } After doing this, the worksheet was cloned with the AutoShapes and Pictures
*** This bug has been marked as a duplicate of 31795 ***