mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
[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
This commit is contained in:
parent
99a463c300
commit
f01a45f9be
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user