try to make CommentsTable more extensible

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895182 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-19 18:09:57 +00:00
parent 72dbcf4702
commit 910724058c
2 changed files with 11 additions and 9 deletions

View File

@ -17,9 +17,9 @@
package org.apache.poi.xssf.model; package org.apache.poi.xssf.model;
import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.xssf.usermodel.XSSFComment; import org.apache.poi.xssf.usermodel.XSSFComment;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import java.util.Iterator; import java.util.Iterator;
@ -54,7 +54,7 @@ public interface Comments {
* @return cell comment if one exists, otherwise returns null * @return cell comment if one exists, otherwise returns null
* @since POI 5.2.0 * @since POI 5.2.0
*/ */
public XSSFComment findCellComment(XSSFSheet sheet, CellAddress cellAddress); public XSSFComment findCellComment(Sheet sheet, CellAddress cellAddress);
/** /**
* Remove the comment at cellRef location, if one exists * Remove the comment at cellRef location, if one exists
@ -84,7 +84,7 @@ public interface Comments {
* @return new XSSFComment * @return new XSSFComment
* @since POI 5.2.0 * @since POI 5.2.0
*/ */
XSSFComment createNewComment(XSSFSheet sheet, ClientAnchor clientAnchor); XSSFComment createNewComment(Sheet sheet, ClientAnchor clientAnchor);
/** /**
* Called after the reference is updated, so that * Called after the reference is updated, so that

View File

@ -25,9 +25,11 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import com.microsoft.schemas.vml.CTShape;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellAddress; import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal; import org.apache.poi.util.Removal;
@ -212,13 +214,13 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
* @since POI 5.2.0 * @since POI 5.2.0
*/ */
@Override @Override
public XSSFComment findCellComment(XSSFSheet sheet, CellAddress cellAddress) { public XSSFComment findCellComment(Sheet sheet, CellAddress cellAddress) {
CTComment ctComment = getCTComment(cellAddress); CTComment ctComment = getCTComment(cellAddress);
if(ctComment == null) { if(ctComment == null) {
return null; return null;
} }
XSSFVMLDrawing vml = sheet.getVMLDrawing(false); XSSFVMLDrawing vml = sheet instanceof XSSFSheet ? ((XSSFSheet)sheet).getVMLDrawing(false) : null;
return new XSSFComment(this, ctComment, return new XSSFComment(this, ctComment,
vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn())); vml == null ? null : vml.findCommentShape(cellAddress.getRow(), cellAddress.getColumn()));
} }
@ -257,10 +259,10 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
* @since POI 5.2.0 * @since POI 5.2.0
*/ */
@Override @Override
public XSSFComment createNewComment(XSSFSheet sheet, ClientAnchor clientAnchor) { public XSSFComment createNewComment(Sheet sheet, ClientAnchor clientAnchor) {
XSSFVMLDrawing vml = sheet.getVMLDrawing(true); XSSFVMLDrawing vml = sheet instanceof XSSFSheet ? ((XSSFSheet)sheet).getVMLDrawing(true) : null;
com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape(); CTShape vmlShape = vml == null ? null : vml.newCommentShape();
if (clientAnchor instanceof XSSFClientAnchor && ((XSSFClientAnchor)clientAnchor).isSet()) { if (vmlShape != null && clientAnchor instanceof XSSFClientAnchor && ((XSSFClientAnchor)clientAnchor).isSet()) {
// convert offsets from emus to pixels since we get a // convert offsets from emus to pixels since we get a
// DrawingML-anchor // DrawingML-anchor
// but create a VML Drawing // but create a VML Drawing