From: Yegor Kozlov Date: Wed, 20 Jul 2011 12:29:27 +0000 (+0000) Subject: fixed bug 51470 - avoid exception when cloning XSSF sheets with background images X-Git-Tag: REL_3_8_BETA4~127 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=31624647c29cec6f858bbfe29c79e0323fd7ac74;p=poi.git fixed bug 51470 - avoid exception when cloning XSSF sheets with background images git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148724 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 2ca1abd0c9..6019d3c14c 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51470 - avoid exception when cloning XSSF sheets with background images 51481 - Fixed autofilters in HSSF to avoid warnings in Excel 2007 51533 - Avoid exception when changing name of a sheet containing shared formulas Support for appending images to existing drawings in HSSF diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java index d81391035d..311573618a 100644 --- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java @@ -233,7 +233,7 @@ public class POIXMLDocumentPart { * * @param part the child to add */ - protected final void addRelation(String id,POIXMLDocumentPart part){ + public final void addRelation(String id,POIXMLDocumentPart part){ relations.put(id,part); part.incrementRelationCounter(); } 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 d8689d87ad..9b0c7219af 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -385,6 +385,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable rels = srcSheet.getRelations(); + for(POIXMLDocumentPart r : rels) { + PackageRelationship rel = r.getPackageRelationship(); + clonedSheet.getPackagePart().addRelationship(rel.getTargetURI(), rel.getTargetMode(),rel.getRelationshipType()); + clonedSheet.addRelation(rel.getId(), r); + } + return clonedSheet; } 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 70b38b636d..364e4120d6 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -1157,4 +1157,16 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { // assertEquals("FFEEECE1", cA4_EEECE1.getCellStyle().getFillForegroundXSSFColor().getARGBHex()); // assertEquals("FF1F497D", cA5_1F497D.getCellStyle().getFillForegroundXSSFColor().getARGBHex()); } + + public void test51470() throws Exception { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51470.xlsx"); + XSSFSheet sh0 = wb.getSheetAt(0); + XSSFSheet sh1 = wb.cloneSheet(0); + List rels0 = sh0.getRelations(); + List rels1 = sh1.getRelations(); + assertEquals(1, rels0.size()); + assertEquals(1, rels1.size()); + + assertEquals(rels0.get(0).getPackageRelationship(), rels1.get(0).getPackageRelationship()); + } } diff --git a/test-data/spreadsheet/51470.xlsx b/test-data/spreadsheet/51470.xlsx new file mode 100644 index 0000000000..01768afdea Binary files /dev/null and b/test-data/spreadsheet/51470.xlsx differ