apache poi的注释

本文概述

  • 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的注释

文章图片

    推荐阅读