From: Dominik Stadler Date: Wed, 11 Mar 2015 18:24:49 +0000 (+0000) Subject: Bug 56467: Fix cloning of sheets with pictures X-Git-Tag: REL_3_12_FINAL~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9d73215957a8ebccf6dee5826711ea0209afa905;p=poi.git Bug 56467: Fix cloning of sheets with pictures git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1665959 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 41a6d613ff..499c3db08e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -576,13 +576,17 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable 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()); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index ae43d81498..ad9c3ad6f8 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -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(); + } + } }