import java.io.FileOutputStream; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.RichTextString; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook; public class TestePoi { public static void main(String[] args) throws Throwable { // Workbook wb = new HSSFWorkbook(); Workbook wb = new SXSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(1); Cell cell = row.createCell(0); 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"); // Assign the comment to the cell cell.setCellComment(comment); FileOutputStream out = new FileOutputStream("o:\\gpd\\nicolas\\sxssf.xlsx"); wb.write(out); out.close(); } }