You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2021/10/21 14:17:32 UTC
svn commit: r1894450 - in /poi/trunk:
poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
test-data/spreadsheet/no_drawing_patriarch.xlsx
Author: centic
Date: Thu Oct 21 14:17:31 2021
New Revision: 1894450
URL: http://svn.apache.org/viewvc?rev=1894450&view=rev
Log:
Avoid NullPointerException when cloning sheets where there is no drawing patriarch
Added:
poi/trunk/test-data/spreadsheet/no_drawing_patriarch.xlsx
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1894450&r1=1894449&r2=1894450&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Thu Oct 21 14:17:31 2021
@@ -677,19 +677,22 @@ public class XSSFWorkbook extends POIXML
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;
}
Added: poi/trunk/test-data/spreadsheet/no_drawing_patriarch.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/no_drawing_patriarch.xlsx?rev=1894450&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/no_drawing_patriarch.xlsx (added) and poi/trunk/test-data/spreadsheet/no_drawing_patriarch.xlsx Thu Oct 21 14:17:31 2021 differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org