diff options
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java | 29 | ||||
-rw-r--r-- | test-data/spreadsheet/no_drawing_patriarch.xlsx | bin | 0 -> 672414 bytes |
2 files changed, 16 insertions, 13 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 2b67475b0b..8b80963730 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 @@ -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; } diff --git a/test-data/spreadsheet/no_drawing_patriarch.xlsx b/test-data/spreadsheet/no_drawing_patriarch.xlsx Binary files differnew file mode 100644 index 0000000000..47f34a0314 --- /dev/null +++ b/test-data/spreadsheet/no_drawing_patriarch.xlsx |