Apache POI Excel 创建注释
评论是与单元格关联的富文本注释。评论内容与单元格分开存储,并显示在单独但与单元格相关联的文本框中。
使用 createComment() 方法创建评论。
让我们看一个示例,其中我们正在创建与单元格关联的评论消息。
Apache POI 评论示例
package com.yiidian;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
import java.io.IOException;
public class CellComments {
public static void main(String[] args) throws IOException {
try (FileOutputStream out = new FileOutputStream("yiidian.xls")) {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Comment Sheet");
HSSFPatriarch hpt = sheet.createDrawingPatriarch();
HSSFCell cell1 = sheet.createRow(3).createCell(1);
cell1.setCellValue("Excel Comment Example");
// Setting size and position of the comment in worksheet
HSSFComment comment1 = hpt.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
// Setting comment text
comment1.setString(new HSSFRichTextString("It is a comment"));
// Associating comment to the cell
cell1.setCellComment(comment1);
wb.write(out);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
输出结果为:
热门文章
优秀文章