java poi给sheet表格中的某个单元格添加批注

// 创建工作簿
XSSFWorkbook workBook = new XSSFWorkbook(inputStream);
// 创建sheet
XSSFSheet sheet = workBook.createSheet(sheetName);
XSSFDrawing draw = newSheet.createDrawingPatriarch();
// 定义注释的大小和位置
/*
 * @param dx1  the x coordinate within the first cell.
 * @param dy1  the y coordinate within the first cell.
 * @param dx2  the x coordinate within the second cell.
 * @param dy2  the y coordinate within the second cell.
 * @param col1 the column (0 based) of the first cell.
 * @param row1 the row (0 based) of the first cell.
 * @param col2 the column (0 based) of the second cell.
 * @param row2 the row (0 based) of the second cell.
 */
XSSFComment comment = draw.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 4, 2, 9, 7));
XSSFRichTextString rtf = new XSSFRichTextString("添加批注内容!");
XSSFFont commentFormatter = workBook.createFont();
commentFormatter.setFontName("宋体");
//设置字体大小
commentFormatter.setFontHeightInPoints((short) 9);
rtf.applyFont(commentFormatter);
comment.setString(rtf);
comment.setAuthor("Zhihui Li");
// 将批注添加到单元格对象中
sheet.getRow(rowIndex).getCell(columnIndex).setCellComment(comment);

如果有不熟悉如何操作Excel的,可以参考前面的博文:
poi操作excel总结

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值