Avoid NullPointerException when cloning sheets where there is no drawing patriarch

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894450 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2021-10-21 14:17:31 +00:00
parent 684f35d3cb
commit 0727874584
2 changed files with 16 additions and 13 deletions

View File

@ -677,19 +677,22 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
clonedDg.getCTDrawing().set(dg.getCTDrawing().copy());
// Clone drawing relations
List<RelationPart> srcRels = srcSheet.getDrawingPatriarch().getRelationParts();
for (RelationPart rp : srcRels) {
POIXMLDocumentPart r = rp.getDocumentPart();
if (r instanceof XSSFChart) {
// Replace chart relation part with new relationship, cloning the chart's content
RelationPart chartPart = clonedDg.createChartRelationPart();
XSSFChart chart = chartPart.getDocumentPart();
chart.importContent((XSSFChart)r);
chart.replaceReferences(clonedSheet);
} else {
addRelation(rp, clonedDg);
}
}
XSSFDrawing drawingPatriarch = srcSheet.getDrawingPatriarch();
if (drawingPatriarch != null) {
List<RelationPart> srcRels = drawingPatriarch.getRelationParts();
for (RelationPart rp : srcRels) {
POIXMLDocumentPart r = rp.getDocumentPart();
if (r instanceof XSSFChart) {
// Replace chart relation part with new relationship, cloning the chart's content
RelationPart chartPart = clonedDg.createChartRelationPart();
XSSFChart chart = chartPart.getDocumentPart();
chart.importContent((XSSFChart) r);
chart.replaceReferences(clonedSheet);
} else {
addRelation(rp, clonedDg);
}
}
}
}
return clonedSheet;
}

Binary file not shown.