本文概述
- Apache POI注释示例
为了创建注释,使用createComment()方法。
让我们看一个示例,在该示例中,我们将创建与单元格关联的评论消息。
Apache POI注释示例
package poiexample;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFComment;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class CellComments {
public static void main(String[] args) throws IOException{
try (FileOutputStream out = new FileOutputStream("srcmini.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());
}
}
}
【apache poi的注释】输出:
文章图片
推荐阅读
- apache poi microsoft word文档
- apache poi样式化形状
- apache poi重写
- apache poi读取单元内容
- apache poi移位行
- apache poi页码
- apache poi概述
- apache poi单元格中的换行
- apache poi excel图片