]> source.dussan.org Git - poi.git/commitdiff
Bug 56467: Fix cloning of sheets with pictures
authorDominik Stadler <centic@apache.org>
Wed, 11 Mar 2015 18:24:49 +0000 (18:24 +0000)
committerDominik Stadler <centic@apache.org>
Wed, 11 Mar 2015 18:24:49 +0000 (18:24 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1665959 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 41a6d613ffbeccc43a9dcc9ee4d172effebe6b12..499c3db08ea1e2a8401cd14215dbbf6c79434e51 100644 (file)
@@ -576,13 +576,17 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
             // copy drawing contents
             clonedDg.getCTDrawing().set(dg.getCTDrawing());
 
+            clonedDg = clonedSheet.createDrawingPatriarch();
+            
             // Clone drawing relations
             List<POIXMLDocumentPart> srcRels = srcSheet.createDrawingPatriarch().getRelations();
             for (POIXMLDocumentPart rel : srcRels) {
                 PackageRelationship relation = rel.getPackageRelationship();
-                clonedSheet
-                        .createDrawingPatriarch()
-                        .getPackagePart()
+
+                clonedDg.addRelation(relation.getId(), rel);
+                
+                clonedDg
+                                               .getPackagePart()
                         .addRelationship(relation.getTargetURI(), relation.getTargetMode(),
                                 relation.getRelationshipType(), relation.getId());
             }
index ae43d814980c3df1ef971a6df494b27148208a47..ad9c3ad6f874ba4f2e3ce29809ca1a0308476fd9 100644 (file)
@@ -31,6 +31,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.Calendar;
 import java.util.List;
 
@@ -2262,4 +2263,31 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
             wb.close();
         }
     }
+    
+    @Test
+    public void test56467() throws IOException {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("picture.xlsx");
+        try {
+            Sheet orig = wb.getSheetAt(0);
+            assertNotNull(orig);
+            
+            Sheet sheet = wb.cloneSheet(0);
+            Drawing drawing = sheet.createDrawingPatriarch();
+            for (XSSFShape shape : ((XSSFDrawing) drawing).getShapes()) {
+                if (shape instanceof XSSFPicture) {
+                    XSSFPictureData pictureData = ((XSSFPicture) shape).getPictureData();
+                    assertNotNull(pictureData);
+                }
+            }
+            
+//            OutputStream out = new FileOutputStream("/tmp/56467.xls");
+//            try {
+//             wb.write(out);
+//            } finally {
+//             out.close();
+//            }
+        } finally {
+               wb.close();
+        }
+    }
 }