Search in sources :

Example 1 with CTCommentList

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList 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 2 with CTCommentList

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList in project poi by apache.

the class TestCommentsTable method getCellComment.

@Test
public void getCellComment() throws Exception {
    CommentsTable sheetComments = new CommentsTable();
    CTComments comments = sheetComments.getCTComments();
    CTCommentList commentList = comments.getCommentList();
    // Create 2 comments for A1 and A" cells
    CTComment comment0 = commentList.insertNewComment(0);
    comment0.setRef("A1");
    CTRst ctrst0 = CTRst.Factory.newInstance();
    ctrst0.setT(TEST_A1_TEXT);
    comment0.setText(ctrst0);
    CTComment comment1 = commentList.insertNewComment(0);
    comment1.setRef("A2");
    CTRst ctrst1 = CTRst.Factory.newInstance();
    ctrst1.setT(TEST_A2_TEXT);
    comment1.setText(ctrst1);
    // test finding the right comment for a cell
    assertSame(comment0, sheetComments.getCTComment(new CellAddress("A1")));
    assertSame(comment1, sheetComments.getCTComment(new CellAddress("A2")));
    assertNull(sheetComments.getCTComment(new CellAddress("A3")));
}
Also used : CTCommentList(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList) CellAddress(org.apache.poi.ss.util.CellAddress) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) CTComments(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments) Test(org.junit.Test)

Aggregations

CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)2 CTCommentList (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList)2 CellAddress (org.apache.poi.ss.util.CellAddress)1 Test (org.junit.Test)1 CTComments (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments)1 CTRst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)1