use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestXSSFComment method testBug58175a.
@Ignore("Used for manual testing with opening the resulting Workbook in Excel")
@Test
public void testBug58175a() throws IOException {
Workbook wb = new SXSSFWorkbook();
try {
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(1);
Cell cell = row.createCell(3);
cell.setCellValue("F4");
Drawing<?> drawing = sheet.createDrawingPatriarch();
CreationHelper factory = wb.getCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum() + 3);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Hello, World!");
comment.setString(str);
comment.setAuthor("Apache POI");
/* fixed the problem as well
* comment.setColumn(cell.getColumnIndex());
* comment.setRow(cell.getRowIndex());
*/
// Assign the comment to the cell
cell.setCellComment(comment);
OutputStream out = new FileOutputStream("C:\\temp\\58175.xlsx");
try {
wb.write(out);
} finally {
out.close();
}
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestXSSFComment method bug57838DeleteRowsWthCommentsBug.
@Test
public void bug57838DeleteRowsWthCommentsBug() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57838.xlsx");
Sheet sheet = wb.getSheetAt(0);
Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNotNull(comment1);
Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
assertNotNull(comment2);
Row row = sheet.getRow(2);
assertNotNull(row);
// Remove row from index 2
sheet.removeRow(row);
row = sheet.getRow(2);
// Row is null since we deleted it.
assertNull(row);
comment1 = sheet.getCellComment(new CellAddress(2, 1));
// comment should be null but will fail due to bug
assertNull(comment1);
comment2 = sheet.getCellComment(new CellAddress(2, 2));
// comment should be null but will fail due to bug
assertNull(comment2);
wb.close();
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestCommentsTable method writeRead.
@Test
public void writeRead() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("WithVariousData.xlsx");
XSSFSheet sheet1 = workbook.getSheetAt(0);
XSSFSheet sheet2 = workbook.getSheetAt(1);
assertTrue(sheet1.hasComments());
assertFalse(sheet2.hasComments());
// Change on comment on sheet 1, and add another into
// sheet 2
Row r5 = sheet1.getRow(4);
Comment cc5 = r5.getCell(2).getCellComment();
cc5.setAuthor("Apache POI");
cc5.setString(new XSSFRichTextString("Hello!"));
Row r2s2 = sheet2.createRow(2);
Cell c1r2s2 = r2s2.createCell(1);
assertNull(c1r2s2.getCellComment());
Drawing<?> dg = sheet2.createDrawingPatriarch();
Comment cc2 = dg.createCellComment(new XSSFClientAnchor());
cc2.setAuthor("Also POI");
cc2.setString(new XSSFRichTextString("A new comment"));
c1r2s2.setCellComment(cc2);
// Save, and re-load the file
workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);
// Check we still have comments where we should do
sheet1 = workbook.getSheetAt(0);
sheet2 = workbook.getSheetAt(1);
assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
// And check they still have the contents they should do
assertEquals("Apache POI", sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
assertEquals("Nick Burch", sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
assertEquals("Also POI", sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
assertEquals("Hello!", sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestXSSFSheetShiftRows method testBug57828_OnlyOneCommentShiftedInRow.
/** Shifting rows with cell comments only shifts comments from first such cell. Other cell comments not shifted */
@Test
public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNotNull(comment1);
Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
assertNotNull(comment2);
Comment comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNull("NO comment in (1,1) and it should be null", comment3);
sheet.shiftRows(2, 2, -1);
comment3 = sheet.getCellComment(new CellAddress(1, 1));
assertNotNull("Comment in (2,1) moved to (1,1) so its not null now.", comment3);
comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNull("No comment currently in (2,1) and hence it is null", comment1);
comment2 = sheet.getCellComment(new CellAddress(1, 2));
assertNotNull("Comment in (2,2) should have moved as well because of shift rows. But its not", comment2);
wb.close();
}
use of org.apache.poi.ss.usermodel.Comment in project poi by apache.
the class TestXSSFSheetShiftRows method testBug56017.
/** Shifting rows with comment result - Unreadable content error and comment deletion */
@Test
public void testBug56017() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
Sheet sheet = wb.getSheetAt(0);
Comment comment = sheet.getCellComment(new CellAddress(0, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
sheet.shiftRows(0, 1, 1);
// comment in row 0 is gone
comment = sheet.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheet.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
Workbook wbBack = XSSFTestDataSamples.writeOutAndReadBack(wb);
wb.close();
assertNotNull(wbBack);
Sheet sheetBack = wbBack.getSheetAt(0);
// comment in row 0 is gone
comment = sheetBack.getCellComment(new CellAddress(0, 0));
assertNull(comment);
// comment is now in row 1
comment = sheetBack.getCellComment(new CellAddress(1, 0));
assertNotNull(comment);
assertEquals("Amdocs", comment.getAuthor());
assertEquals("Amdocs:\ntest\n", comment.getString().getString());
wbBack.close();
}
Aggregations