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