use of org.apache.poi.ss.usermodel.Comment in project Gargoyle by callakrsos.
the class ExcelUtil method addComment.
/**
* 특정셀에 코멘트를 추가한다.
*
* @param sheet
* @param cell
* @param commentText
* @return
*/
public static void addComment(Sheet sheet, Cell cell, String commentText) {
XSSFDrawing patr = (XSSFDrawing) sheet.createDrawingPatriarch();
Comment comment = patr.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
comment.setString(new XSSFRichTextString(commentText));
cell.setCellComment(comment);
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class CellComments method main.
public static void main(String[] args) throws IOException {
Workbook wb = new XSSFWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet();
Cell cell1 = sheet.createRow(3).createCell(5);
cell1.setCellValue("F4");
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
Comment comment1 = drawing.createCellComment(anchor);
RichTextString str1 = factory.createRichTextString("Hello, World!");
comment1.setString(str1);
comment1.setAuthor("Apache POI");
cell1.setCellComment(comment1);
Cell cell2 = sheet.createRow(2).createCell(2);
cell2.setCellValue("C3");
Comment comment2 = drawing.createCellComment(anchor);
RichTextString str2 = factory.createRichTextString("XSSF can set cell comments");
//apply custom font to the text in the comment
Font font = wb.createFont();
font.setFontName("Arial");
font.setFontHeightInPoints((short) 14);
font.setBold(true);
font.setColor(IndexedColors.RED.getIndex());
str2.applyFont(font);
comment2.setString(str2);
comment2.setAuthor("Apache POI");
comment2.setAddress(new CellAddress("C3"));
String fname = "comments.xlsx";
FileOutputStream out = new FileOutputStream(fname);
wb.write(out);
out.close();
wb.close();
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestXSSFSheet method addComments.
private void addComments(CreationHelper helper, Sheet sheet) {
Drawing<?> drawing = sheet.createDrawingPatriarch();
for (int i = 0; i < 2; i++) {
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(0 + i);
anchor.setCol2(2);
anchor.setRow2(3 + i);
Comment comment = drawing.createCellComment(anchor);
comment.setString(helper.createRichTextString("BugTesting"));
Row row = sheet.getRow(0 + i);
if (row == null) {
row = sheet.createRow(0 + i);
}
Cell cell = row.getCell(0);
if (cell == null) {
cell = row.createCell(0);
}
cell.setCellComment(comment);
}
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestCommentsTable method bug54920.
@Test
public void bug54920() throws IOException {
final Workbook workbook = new XSSFWorkbook();
final Sheet sheet = workbook.createSheet("sheet01");
// create anchor
CreationHelper helper = sheet.getWorkbook().getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
// place comment in A1
// NOTE - only occurs if a comment is placed in A1 first
Cell A1 = getCell(sheet, 0, 0);
//Cell A1 = getCell(sheet, 2, 2);
Drawing<?> drawing = sheet.createDrawingPatriarch();
setComment(sheet, A1, drawing, "for A1", helper, anchor);
// find comment in A1 before we set the comment in B2
Comment commentA1 = A1.getCellComment();
assertNotNull("Should still find the previous comment in A1, but had null", commentA1);
assertEquals("should find correct comment in A1, but had null: " + commentA1, "for A1", commentA1.getString().getString());
// place comment in B2, according to Bug 54920 this removes the comment in A1!
Cell B2 = getCell(sheet, 1, 1);
setComment(sheet, B2, drawing, "for B2", helper, anchor);
// find comment in A1
Comment commentB2 = B2.getCellComment();
assertEquals("should find correct comment in B2, but had null: " + commentB2, "for B2", commentB2.getString().getString());
// find comment in A1
commentA1 = A1.getCellComment();
assertNotNull("Should still find the previous comment in A1, but had null", commentA1);
assertEquals("should find correct comment in A1, but had null: " + commentA1, "for A1", commentA1.getString().getString());
workbook.close();
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestCommentsTable method existing.
@Test
public void existing() {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
Sheet sheet1 = workbook.getSheetAt(0);
Sheet sheet2 = workbook.getSheetAt(1);
assertTrue(((XSSFSheet) sheet1).hasComments());
assertFalse(((XSSFSheet) sheet2).hasComments());
// Comments should be in C5 and C7
Row r5 = sheet1.getRow(4);
Row r7 = sheet1.getRow(6);
assertNotNull(r5.getCell(2).getCellComment());
assertNotNull(r7.getCell(2).getCellComment());
// Check they have what we expect
// TODO: Rich text formatting
Comment cc5 = r5.getCell(2).getCellComment();
Comment cc7 = r7.getCell(2).getCellComment();
assertEquals("Nick Burch", cc5.getAuthor());
assertEquals("Nick Burch:\nThis is a comment", cc5.getString().getString());
assertEquals(4, cc5.getRow());
assertEquals(2, cc5.getColumn());
assertEquals("Nick Burch", cc7.getAuthor());
assertEquals("Nick Burch:\nComment #1\n", cc7.getString().getString());
assertEquals(6, cc7.getRow());
assertEquals(2, cc7.getColumn());
}
Aggregations