个性化阅读
专注于IT技术分析

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());
     }
     }
 }

输出:

赞(0)
未经允许不得转载:srcmini » apache poi的注释

评论 抢沙发

评论前必须登录!