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;
}
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")));
}
Aggregations