import java.util.Iterator;
import java.util.Map;
+import com.microsoft.schemas.vml.CTShape;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Units;
+import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFComment;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFVMLDrawing;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
return commentRefs.keySet().iterator();
}
+ /**
+ * Create a new comment and add to the CommentTable.
+ * @param sheet sheet to add comment to
+ * @param clientAnchor the anchor for this comment
+ * @return new XSSFComment
+ * @since POI 5.2.0
+ */
+ public XSSFComment createNewComment(XSSFSheet sheet, XSSFClientAnchor clientAnchor) {
+ XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
+ com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
+ if (clientAnchor.isSet()) {
+ // convert offsets from emus to pixels since we get a
+ // DrawingML-anchor
+ // but create a VML Drawing
+ int dx1Pixels = clientAnchor.getDx1() / Units.EMU_PER_PIXEL;
+ int dy1Pixels = clientAnchor.getDy1() / Units.EMU_PER_PIXEL;
+ int dx2Pixels = clientAnchor.getDx2() / Units.EMU_PER_PIXEL;
+ int dy2Pixels = clientAnchor.getDy2() / Units.EMU_PER_PIXEL;
+ String position = clientAnchor.getCol1() + ", " + dx1Pixels + ", " + clientAnchor.getRow1() + ", " + dy1Pixels + ", " +
+ clientAnchor.getCol2() + ", " + dx2Pixels + ", " + clientAnchor.getRow2() + ", " + dy2Pixels;
+ vmlShape.getClientDataArray(0).setAnchorArray(0, position);
+ }
+ CellAddress ref = new CellAddress(clientAnchor.getRow1(), clientAnchor.getCol1());
+
+ if (findCellComment(ref) != null) {
+ throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
+ }
+
+ return new XSSFComment(this, newComment(ref), vmlShape);
+ }
+
/**
* Refresh Map<CellAddress, CTComment> commentRefs cache,
* Calls that use the commentRefs cache will perform in O(1)
import org.apache.poi.openxml4j.opc.TargetMode;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.ImageUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet();
- // create comments and vmlDrawing parts if they don't exist
CommentsTable comments = sheet.getCommentsTable(true);
- XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
- com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
- if (ca.isSet()) {
- // convert offsets from emus to pixels since we get a
- // DrawingML-anchor
- // but create a VML Drawing
- int dx1Pixels = ca.getDx1() / Units.EMU_PER_PIXEL;
- int dy1Pixels = ca.getDy1() / Units.EMU_PER_PIXEL;
- int dx2Pixels = ca.getDx2() / Units.EMU_PER_PIXEL;
- int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL;
- String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca
- .getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
- vmlShape.getClientDataArray(0).setAnchorArray(0, position);
- }
- CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
-
- if (comments.findCellComment(ref) != null) {
- throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
- }
-
- return new XSSFComment(comments, comments.newComment(ref), vmlShape);
+ return comments.createNewComment(getSheet(), ca);
}
/**
}
/**
- * Get VML drawing for this sheet (aka 'legacy' drawing)
+ * 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
*/
- protected XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
+ @Internal
+ public XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
XSSFVMLDrawing drawing = null;
CTLegacyDrawing ctDrawing = getCTLegacyDrawing();
if(ctDrawing == null) {
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.schemas.vmldrawing.XmlDocument;
+import org.apache.poi.util.Internal;
import org.apache.poi.util.ReplacingInputStream;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
grpCur.dispose();
}
- protected CTShape newCommentShape(){
+ /**
+ * This method is for internal POI use only.
+ */
+ @Internal
+ public CTShape newCommentShape() {
CTGroup grp = CTGroup.Factory.newInstance();
CTShape shape = grp.addNewShape();