Search in sources :

Example 6 with CTComment

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

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

the class TestCommentsTable method removeComment.

@Test
public void removeComment() throws Exception {
    final CellAddress addrA1 = new CellAddress("A1");
    final CellAddress addrA2 = new CellAddress("A2");
    final CellAddress addrA3 = new CellAddress("A3");
    CommentsTable sheetComments = new CommentsTable();
    CTComment a1 = sheetComments.newComment(addrA1);
    CTComment a2 = sheetComments.newComment(addrA2);
    CTComment a3 = sheetComments.newComment(addrA3);
    assertSame(a1, sheetComments.getCTComment(addrA1));
    assertSame(a2, sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertEquals(3, sheetComments.getNumberOfComments());
    assertTrue(sheetComments.removeComment(addrA1));
    assertEquals(2, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertSame(a2, sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertTrue(sheetComments.removeComment(addrA2));
    assertEquals(1, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertNull(sheetComments.getCTComment(addrA2));
    assertSame(a3, sheetComments.getCTComment(addrA3));
    assertTrue(sheetComments.removeComment(addrA3));
    assertEquals(0, sheetComments.getNumberOfComments());
    assertNull(sheetComments.getCTComment(addrA1));
    assertNull(sheetComments.getCTComment(addrA2));
    assertNull(sheetComments.getCTComment(addrA3));
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) Test(org.junit.Test)

Example 8 with CTComment

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

the class TestXSSFComment method author.

@Test
public void author() {
    CommentsTable sheetComments = new CommentsTable();
    CTComment ctComment = sheetComments.newComment(CellAddress.A1);
    assertEquals(1, sheetComments.getNumberOfAuthors());
    XSSFComment comment = new XSSFComment(sheetComments, ctComment, null);
    assertEquals("", comment.getAuthor());
    comment.setAuthor("Apache POI");
    assertEquals("Apache POI", comment.getAuthor());
    assertEquals(2, sheetComments.getNumberOfAuthors());
    comment.setAuthor("Apache POI");
    assertEquals(2, sheetComments.getNumberOfAuthors());
    comment.setAuthor("");
    assertEquals("", comment.getAuthor());
    assertEquals(2, sheetComments.getNumberOfAuthors());
}
Also used : CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) CommentsTable(org.apache.poi.xssf.model.CommentsTable) Test(org.junit.Test)

Example 9 with CTComment

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

the class TestXSSFComment method getSetRow.

@Test
public void getSetRow() {
    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.setRow(1);
    assertEquals(1, comment.getRow());
    assertEquals(1, new CellReference(ctComment.getRef()).getRow());
    assertEquals(1, vmlShape.getClientDataArray(0).getRowArray(0).intValue());
    comment.setRow(5);
    assertEquals(5, comment.getRow());
    assertEquals(5, new CellReference(ctComment.getRef()).getRow());
    assertEquals(5, vmlShape.getClientDataArray(0).getRowArray(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)

Example 10 with CTComment

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

the class TestXSSFComment method setString.

@Test
public void setString() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();
    XSSFComment comment = sh.createDrawingPatriarch().createCellComment(new XSSFClientAnchor());
    //passing HSSFRichTextString is incorrect
    try {
        comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING));
        fail("expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Only XSSFRichTextString argument is supported", e.getMessage());
    }
    //simple string argument
    comment.setString(TEST_RICHTEXTSTRING);
    assertEquals(TEST_RICHTEXTSTRING, comment.getString().getString());
    //if the text is already set, it should be overridden, not added twice!
    comment.setString(TEST_RICHTEXTSTRING);
    CTComment ctComment = comment.getCTComment();
    XmlObject[] obj = ctComment.selectPath("declare namespace w='" + NS_SPREADSHEETML + "' .//w:text");
    assertEquals(1, obj.length);
    assertEquals(TEST_RICHTEXTSTRING, comment.getString().getString());
    //sequential call of comment.getString() should return the same XSSFRichTextString object
    assertSame(comment.getString(), comment.getString());
    XSSFRichTextString richText = new XSSFRichTextString(TEST_RICHTEXTSTRING);
    XSSFFont font1 = wb.createFont();
    font1.setFontName("Tahoma");
    font1.setFontHeight(8.5);
    font1.setItalic(true);
    font1.setColor(IndexedColors.BLUE_GREY.getIndex());
    richText.applyFont(0, 5, font1);
    //check the low-level stuff
    comment.setString(richText);
    obj = ctComment.selectPath("declare namespace w='" + NS_SPREADSHEETML + "' .//w:text");
    assertEquals(1, obj.length);
    assertSame(comment.getString(), richText);
    //check that the rich text is set in the comment
    CTRPrElt rPr = richText.getCTRst().getRArray(0).getRPr();
    assertEquals(true, rPr.getIArray(0).getVal());
    assertEquals(8.5, rPr.getSzArray(0).getVal(), 0);
    assertEquals(IndexedColors.BLUE_GREY.getIndex(), rPr.getColorArray(0).getIndexed());
    assertEquals("Tahoma", rPr.getRFontArray(0).getVal());
    assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt) XmlObject(org.apache.xmlbeans.XmlObject) 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