From f01a45f9bec903aa4a73f49a5cb9e8df941a9bbc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 22 Jul 2021 15:40:56 +0000 Subject: [PATCH] [bug-64759] ignore unknown relationships when cloning sheets git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891722 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 9 +++++++-- .../java/org/apache/poi/xssf/TestXSSFCloneSheet.java | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index b2d5fe7a49..bcf0aee728 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -688,9 +688,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su } /** + * Modified in POI 5.0.1 to only log issues with unknown relationship types + * - see https://bz.apache.org/bugzilla/show_bug.cgi?id=64759 + * * @since 3.14-Beta1 */ - private static void addRelation(RelationPart rp, POIXMLDocumentPart target) { + private static boolean addRelation(RelationPart rp, POIXMLDocumentPart target) { PackageRelationship rel = rp.getRelationship(); if (rel.getTargetMode() == TargetMode.EXTERNAL) { target.getPackagePart().addRelationship( @@ -699,10 +702,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su XSSFRelation xssfRel = XSSFRelation.getInstance(rel.getRelationshipType()); if (xssfRel == null) { // Don't copy all relations blindly, but only the ones we know about - throw new POIXMLException("Can't clone sheet - unknown relation type found: "+rel.getRelationshipType()); + LOG.atWarn().log("Can't clone sheet relationship (some data will be lost in the cloned sheet) - unknown relation type found: {}", rel.getRelationshipType()); + return false; } target.addRelation(rel.getId(), xssfRel, rp.getDocumentPart()); } + return true; } /** diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java index b3c2896fd8..f002e3231d 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/TestXSSFCloneSheet.java @@ -118,4 +118,14 @@ class TestXSSFCloneSheet extends BaseTestCloneSheet { } } + @Test + void test64759() throws IOException { + try (Workbook template_wb = XSSFTestDataSamples.openSampleWorkbook("right-to-left.xlsx")) { + Sheet template_sh = template_wb.getSheetAt(0); + assertNotNull(template_sh); + Sheet source_sh = template_wb.cloneSheet(0); + assertNotNull(source_sh); + } + } + } -- 2.39.5