diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java index dcb35e7643..1ad6d0f7e2 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/model/CommentsTable.java @@ -34,6 +34,7 @@ import org.apache.poi.ss.util.CellAddress; import org.apache.poi.util.Internal; import org.apache.poi.util.Removal; import org.apache.poi.util.Units; +import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFComment; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -220,7 +221,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { return null; } - XSSFVMLDrawing vml = sheet instanceof XSSFSheet ? ((XSSFSheet)sheet).getVMLDrawing(false) : null; + XSSFVMLDrawing vml = getVMLDrawing(sheet, false); return new XSSFComment(this, ctComment, vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn())); } @@ -260,7 +261,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { */ @Override public XSSFComment createNewComment(Sheet sheet, ClientAnchor clientAnchor) { - XSSFVMLDrawing vml = sheet instanceof XSSFSheet ? ((XSSFSheet)sheet).getVMLDrawing(true) : null; + XSSFVMLDrawing vml = getVMLDrawing(sheet, true); CTShape vmlShape = vml == null ? null : vml.newCommentShape(); if (vmlShape != null && clientAnchor instanceof XSSFClientAnchor && ((XSSFClientAnchor)clientAnchor).isSet()) { // convert offsets from emus to pixels since we get a @@ -365,4 +366,13 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments { comments.getAuthors().insertAuthor(index, author); return index; } + + private XSSFVMLDrawing getVMLDrawing(Sheet sheet, boolean autocreate) { + if (sheet instanceof XSSFSheet) { + return ((XSSFSheet)sheet).getVMLDrawing(autocreate); + } else if (sheet instanceof SXSSFSheet) { + return ((SXSSFSheet)sheet).getVMLDrawing(autocreate); + } + return null; + } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index dff6896147..37d0ca5c4b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -47,12 +47,7 @@ import org.apache.poi.ss.util.PaneInformation; import org.apache.poi.ss.util.SheetUtil; import org.apache.poi.util.Internal; import org.apache.poi.util.NotImplemented; -import org.apache.poi.xssf.usermodel.XSSFColor; -import org.apache.poi.xssf.usermodel.XSSFComment; -import org.apache.poi.xssf.usermodel.XSSFDataValidation; -import org.apache.poi.xssf.usermodel.XSSFDrawing; -import org.apache.poi.xssf.usermodel.XSSFHyperlink; -import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.*; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr; @@ -349,6 +344,20 @@ public class SXSSFSheet implements Sheet } + /** + * Get VML drawing for this sheet (aka 'legacy' drawing). This method is for internal POI use only. + * + * @param autoCreate if true, then a new VML drawing part is created + * + * @return the VML drawing of {@code null} if the drawing was not found and autoCreate=false + * @since POI 5.2.0 + */ + @Internal + public XSSFVMLDrawing getVMLDrawing(boolean autoCreate) { + XSSFSheet xssfSheet = getWorkbook().getXSSFSheet(this); + return xssfSheet == null ? null : xssfSheet.getVMLDrawing(autoCreate); + } + /** * Returns the CellStyle that applies to the given * (0 based) column, or null if no style has been