]> source.dussan.org Git - poi.git/commitdiff
fixed bug 51470 - avoid exception when cloning XSSF sheets with background images
authorYegor Kozlov <yegor@apache.org>
Wed, 20 Jul 2011 12:29:27 +0000 (12:29 +0000)
committerYegor Kozlov <yegor@apache.org>
Wed, 20 Jul 2011 12:29:27 +0000 (12:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148724 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
test-data/spreadsheet/51470.xlsx [new file with mode: 0644]

index 2ca1abd0c9c5e554d608bec0e71007ddf9dcba00..6019d3c14c5d90768786fc23eadcb850a7105a27 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51470 - avoid exception when cloning XSSF sheets with background images</action>
            <action dev="poi-developers" type="fix">51481 - Fixed autofilters in HSSF to avoid warnings in Excel 2007</action>
            <action dev="poi-developers" type="fix">51533 - Avoid exception when changing name of a sheet containing shared formulas</action>
            <action dev="poi-developers" type="add">Support for appending images to existing drawings in HSSF</action>
index d81391035da338f8541978a85784327b6abbd780..311573618aa43408110e17c8b4493cce5c24a263 100644 (file)
@@ -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();
     }
index d8689d87ad441658bed18417d810ca3825fb9b67..9b0c7219af445f48e3cf03cdc3762eabcbb8af61 100644 (file)
@@ -385,6 +385,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
         }
 
         clonedSheet.setSelected(false);
+
+        // copy sheet's relations
+        List<POIXMLDocumentPart> 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;
     }
 
index 70b38b636d03009d0aebc7d571e2cbcc0c5905f1..364e4120d65456622d9d74d9308fba0ceac89590 100644 (file)
@@ -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<POIXMLDocumentPart> rels0 = sh0.getRelations();
+        List<POIXMLDocumentPart> 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 (file)
index 0000000..01768af
Binary files /dev/null and b/test-data/spreadsheet/51470.xlsx differ