Java ApachePOI评论作者错过了
我正在使用ApachePOI3.8,并尝试使用下面的代码为HSSF工作表运行一个单元格注释示例,但注释中缺少作者Java ApachePOI评论作者错过了,java,excel,apache,apache-poi,Java,Excel,Apache,Apache Poi,我正在使用ApachePOI3.8,并尝试使用下面的代码为HSSF工作表运行一个单元格注释示例,但注释中缺少作者 Workbook wb = new HSSFWorkbook(); //or new HSSFWorkbook(); CreationHelper factory = wb.getCreationHelper(); Sheet sheet = wb.createSheet(); Row row = sheet.createRow(3); Cel
Workbook wb = new HSSFWorkbook(); //or new HSSFWorkbook();
CreationHelper factory = wb.getCreationHelper();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(3);
Cell cell = row.createCell(5);
cell.setCellValue("asdads");
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex()+5);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum()+2);
// Create the comment and set the text+author
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Hello, World! the new world");
comment.setAuthor("roy");
comment.setString(str);
comment.setVisible(Boolean.FALSE);
// Assign the comment to the cell
cell.setCellComment(comment);
System.out.println(comment.getAuthor());
String fname = "C:/Users/roy/Desktop/comment.xls";
FileOutputStream out = new FileOutputStream(fname);
wb.write(out);
out.close();
请提出任何想法正如@Avik在上面指出的,这可以很容易地设置。。。我不认为这是一个bug,因为在Office中,这只是一个方便的功能,因为注释不需要以作者姓名开头,您可以删除它
String author = "roy";
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString(author+":\nHello, World! the new world");
str.applyFont(0, author.length()+2, font);
comment.setAuthor(author);
comment.setString(str);
comment.setVisible(Boolean.FALSE);
// Assign the comment to the cell
cell.setCellComment(comment);
为什么要将setVisible设置为false?你看到评论了吗?我希望评论只在鼠标上方可见,但这与作者无关,代码似乎没有问题,不知道为什么你看不到作者,你能附上你的结果xls吗?请查看图片它似乎是一个小错误。您只需将作者名称设置为setText()的一部分,直到错误得到修复。