Skip to content

Commit b7c14b3

Browse files
committed
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
1 parent 51fdb94 commit b7c14b3

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,17 @@ public XSSFSheet cloneSheet(int sheetNum) {
576576
// copy drawing contents
577577
clonedDg.getCTDrawing().set(dg.getCTDrawing());
578578

579+
clonedDg = clonedSheet.createDrawingPatriarch();
580+
579581
// Clone drawing relations
580582
List<POIXMLDocumentPart> srcRels = srcSheet.createDrawingPatriarch().getRelations();
581583
for (POIXMLDocumentPart rel : srcRels) {
582584
PackageRelationship relation = rel.getPackageRelationship();
583-
clonedSheet
584-
.createDrawingPatriarch()
585-
.getPackagePart()
585+
586+
clonedDg.addRelation(relation.getId(), rel);
587+
588+
clonedDg
589+
.getPackagePart()
586590
.addRelationship(relation.getTargetURI(), relation.getTargetMode(),
587591
relation.getRelationshipType(), relation.getId());
588592
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3131
import java.io.FileInputStream;
3232
import java.io.FileOutputStream;
3333
import java.io.IOException;
34+
import java.io.OutputStream;
3435
import java.util.Calendar;
3536
import java.util.List;
3637

@@ -2262,4 +2263,31 @@ public void testBug56820_Formula2() throws IOException {
22622263
wb.close();
22632264
}
22642265
}
2266+
2267+
@Test
2268+
public void test56467() throws IOException {
2269+
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("picture.xlsx");
2270+
try {
2271+
Sheet orig = wb.getSheetAt(0);
2272+
assertNotNull(orig);
2273+
2274+
Sheet sheet = wb.cloneSheet(0);
2275+
Drawing drawing = sheet.createDrawingPatriarch();
2276+
for (XSSFShape shape : ((XSSFDrawing) drawing).getShapes()) {
2277+
if (shape instanceof XSSFPicture) {
2278+
XSSFPictureData pictureData = ((XSSFPicture) shape).getPictureData();
2279+
assertNotNull(pictureData);
2280+
}
2281+
}
2282+
2283+
// OutputStream out = new FileOutputStream("/tmp/56467.xls");
2284+
// try {
2285+
// wb.write(out);
2286+
// } finally {
2287+
// out.close();
2288+
// }
2289+
} finally {
2290+
wb.close();
2291+
}
2292+
}
22652293
}

0 commit comments

Comments
 (0)