Search in sources :

Example 1 with CTComments

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments 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)

Example 2 with CTComments

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

the class TestXSSFSheet method setCellComment.

@Test
public void setCellComment() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    XSSFDrawing dg = sheet.createDrawingPatriarch();
    XSSFComment comment = dg.createCellComment(new XSSFClientAnchor());
    Cell cell = sheet.createRow(0).createCell(0);
    CommentsTable comments = sheet.getCommentsTable(false);
    CTComments ctComments = comments.getCTComments();
    cell.setCellComment(comment);
    assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
    comment.setAuthor("test A1 author");
    assertEquals("test A1 author", comments.getAuthor((int) ctComments.getCommentList().getCommentArray(0).getAuthorId()));
    workbook.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTComments(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments) CTCell(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell) Cell(org.apache.poi.ss.usermodel.Cell) CommentsTable(org.apache.poi.xssf.model.CommentsTable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 CTComments (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments)2 Cell (org.apache.poi.ss.usermodel.Cell)1 CellAddress (org.apache.poi.ss.util.CellAddress)1 CommentsTable (org.apache.poi.xssf.model.CommentsTable)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 CTCell (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell)1 CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)1 CTCommentList (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList)1 CTRst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)1