Search in sources :

Example 1 with CTComment

use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.

the class CommentsTable method newComment.

/**
     * Create a new comment located` at cell address
     *
     * @param ref the location to add the comment
     * @return a new CTComment located at ref with default author
     */
@Internal
public CTComment newComment(CellAddress ref) {
    CTComment ct = comments.getCommentList().addNewComment();
    ct.setRef(ref.formatAsString());
    ct.setAuthorId(DEFAULT_AUTHOR_ID);
    if (commentRefs != null) {
        commentRefs.put(ref, ct);
    }
    return ct;
}
Also used : CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) Internal(org.apache.poi.util.Internal)

Example 2 with CTComment

use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.

the class CommentsTable method removeComment.

/**
     * Remove the comment at cellRef location, if one exists
     *
     * @param cellRef the location of the comment to remove
     * @return returns true if a comment was removed
     */
public boolean removeComment(CellAddress cellRef) {
    final String stringRef = cellRef.formatAsString();
    CTCommentList lst = comments.getCommentList();
    if (lst != null) {
        CTComment[] commentArray = lst.getCommentArray();
        for (int i = 0; i < commentArray.length; i++) {
            CTComment comment = commentArray[i];
            if (stringRef.equals(comment.getRef())) {
                lst.removeComment(i);
                if (commentRefs != null) {
                    commentRefs.remove(cellRef);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : CTCommentList(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)

Example 3 with CTComment

use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.

the class CommentsTable method getCellComments.

/**
     * Returns all cell comments on this sheet.
     * @return A map of each Comment in this sheet, keyed on the cell address where
     * the comment is located.
     */
public Map<CellAddress, XSSFComment> getCellComments() {
    prepareCTCommentCache();
    final TreeMap<CellAddress, XSSFComment> map = new TreeMap<CellAddress, XSSFComment>();
    for (final Entry<CellAddress, CTComment> e : commentRefs.entrySet()) {
        map.put(e.getKey(), new XSSFComment(this, e.getValue(), null));
    }
    return map;
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) TreeMap(java.util.TreeMap) XSSFComment(org.apache.poi.xssf.usermodel.XSSFComment)

Example 4 with CTComment

use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.

the class TestXSSFComment method constructor.

/**
     * test properties of a newly constructed comment
     */
@Test
public void constructor() {
    CommentsTable sheetComments = new CommentsTable();
    assertNotNull(sheetComments.getCTComments().getCommentList());
    assertNotNull(sheetComments.getCTComments().getAuthors());
    assertEquals(1, sheetComments.getCTComments().getAuthors().sizeOfAuthorArray());
    assertEquals(1, sheetComments.getNumberOfAuthors());
    CTComment ctComment = sheetComments.newComment(CellAddress.A1);
    CTShape vmlShape = CTShape.Factory.newInstance();
    XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
    assertEquals(null, comment.getString());
    assertEquals(0, comment.getRow());
    assertEquals(0, comment.getColumn());
    assertEquals("", comment.getAuthor());
    assertEquals(false, comment.isVisible());
}
Also used : CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) CTShape(com.microsoft.schemas.vml.CTShape) CommentsTable(org.apache.poi.xssf.model.CommentsTable) Test(org.junit.Test)

Example 5 with CTComment

use of org.openxmlformats.schemas.presentationml.x2006.main.CTComment in project poi by apache.

the class TestXSSFComment method getSetCol.

@Test
public void getSetCol() {
    CommentsTable sheetComments = new CommentsTable();
    XSSFVMLDrawing vml = new XSSFVMLDrawing();
    CTComment ctComment = sheetComments.newComment(CellAddress.A1);
    CTShape vmlShape = vml.newCommentShape();
    XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
    comment.setColumn(1);
    assertEquals(1, comment.getColumn());
    assertEquals(1, new CellReference(ctComment.getRef()).getCol());
    assertEquals(1, vmlShape.getClientDataArray(0).getColumnArray(0).intValue());
    comment.setColumn(5);
    assertEquals(5, comment.getColumn());
    assertEquals(5, new CellReference(ctComment.getRef()).getCol());
    assertEquals(5, vmlShape.getClientDataArray(0).getColumnArray(0).intValue());
}
Also used : CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) CTShape(com.microsoft.schemas.vml.CTShape) CellReference(org.apache.poi.ss.util.CellReference) CommentsTable(org.apache.poi.xssf.model.CommentsTable) Test(org.junit.Test)

Aggregations

CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)10 Test (org.junit.Test)7 CommentsTable (org.apache.poi.xssf.model.CommentsTable)4 CTShape (com.microsoft.schemas.vml.CTShape)3 CellAddress (org.apache.poi.ss.util.CellAddress)3 CellReference (org.apache.poi.ss.util.CellReference)2 CTComment (org.openxmlformats.schemas.presentationml.x2006.main.CTComment)2 CTCommentAuthor (org.openxmlformats.schemas.presentationml.x2006.main.CTCommentAuthor)2 CTCommentList (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList)2 TreeMap (java.util.TreeMap)1 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)1 Internal (org.apache.poi.util.Internal)1 XSLFCommentAuthors (org.apache.poi.xslf.usermodel.XSLFCommentAuthors)1 XSLFComments (org.apache.poi.xslf.usermodel.XSLFComments)1 XSLFNotes (org.apache.poi.xslf.usermodel.XSLFNotes)1 XSLFSlideLayout (org.apache.poi.xslf.usermodel.XSLFSlideLayout)1 XSLFSlideMaster (org.apache.poi.xslf.usermodel.XSLFSlideMaster)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFComment (org.apache.poi.xssf.usermodel.XSSFComment)1 XmlObject (org.apache.xmlbeans.XmlObject)1