Cell r1c1 = r1.createCell(0);
r1c1.setCellValue(2.2);
assertEquals(0, s1.getNumberOfComments());
Comment c1 = s1.createComment();
c1.setAuthor("Author 1");
c1.setString(new XSSFRichTextString("Comment 1"));
r1c1.setCellComment(c1);
assertEquals(1, s1.getNumberOfComments());
// Save and re-load
ByteArrayOutputStream baos = new ByteArrayOutputStream();
wb.write(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
wb = new XSSFWorkbook(Package.open(bais));
s1 = (XSSFSheet)wb.getSheetAt(0);
assertEquals(1, s1.getNumberOfComments());
assertNotNull(s1.getRow(0).getCell(0).getCellComment());
assertEquals("Author 1", s1.getRow(0).getCell(0).getCellComment().getAuthor());
assertEquals("Comment 1", s1.getRow(0).getCell(0).getCellComment().getString().getString());
// Now add an orphaned one
Comment c2 = s1.createComment();
c2.setAuthor("Author 2");
c2.setString(new XSSFRichTextString("Second Comment"));
c2.setRow(0);
c2.setColumn((short)1);
assertEquals(2, s1.getNumberOfComments());
// Save and re-load
baos = new ByteArrayOutputStream();
wb.write(baos);