Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在apache poi中使用HSSFClientAnchor创建单元格注释_Java_Apache Poi - Fatal编程技术网

Java 在apache poi中使用HSSFClientAnchor创建单元格注释

Java 在apache poi中使用HSSFClientAnchor创建单元格注释,java,apache-poi,Java,Apache Poi,有人能给我解释一下在创建单元格评论时如何正确使用锚吗?我的手机正在工作,但电子表格发生了变化,我的手机评论出现了问题。这就是我所使用的代码: Comment c = drawing.createCellComment (new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5)); 这主要是通过实验发现的。查看api并不能让它更清晰 根据《快速入门指南》,我还尝试了以下方法,但没有成功: ClientAnchor anchor = c

有人能给我解释一下在创建单元格评论时如何正确使用锚吗?我的手机正在工作,但电子表格发生了变化,我的手机评论出现了问题。这就是我所使用的代码:

 Comment c = drawing.createCellComment (new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short)6, 5));
这主要是通过实验发现的。查看api并不能让它更清晰

根据《快速入门指南》,我还尝试了以下方法,但没有成功:

ClientAnchor anchor = chf.createClientAnchor();
Comment c = drawing.createCellComment(anchor);
c.setString(chf.createRichTextString(message)); 

有点晚了,但这可能会起作用(它对我有效,而快速入门中的ApachePOI示例对我也不起作用):

public void setComment(字符串文本,单元格){
最终地图绘制父权制=新HashMap();
CreationHelper createHelper=cell.getSheet().getWorkbook().getCreationHelper();
HSSFSheet sheet=(HSSFSheet)单元格。getSheet();
HSSFPatriarch DrawingParachers=DrawingParachers.get(表格);
if(drawingparcher==null){
DrawingParator=sheet.createDrawingParator();
绘图家长。放置(图纸,绘图家长);
}
Comment Comment=drawingparcher.createComment(新的HSSFClientAnchor(0,0,0,0,(短)4,2,(短)6,5));
comment.setString(createHelper.createRichTextString(text));
cell.setcellcoment(comment);
}

Erik Pragt

以下代码适用于我的Office2007(xlsx)格式文件。从POI指南中找到了这个 及


这就是我最终要做的。
    public void setComment(String text, Cell cell) {
    final Map<Sheet, HSSFPatriarch> drawingPatriarches = new HashMap<Sheet, HSSFPatriarch>();

    CreationHelper createHelper = cell.getSheet().getWorkbook().getCreationHelper();
    HSSFSheet sheet = (HSSFSheet) cell.getSheet();
    HSSFPatriarch drawingPatriarch = drawingPatriarches.get(sheet);
    if (drawingPatriarch == null) {
        drawingPatriarch = sheet.createDrawingPatriarch();
        drawingPatriarches.put(sheet, drawingPatriarch);
    }

    Comment comment = drawingPatriarch.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
    comment.setString(createHelper.createRichTextString(text));
    cell.setCellComment(comment);
}
protected void setCellComment(Cell cell, String message) {
    Drawing drawing = cell.getSheet().createDrawingPatriarch();
    CreationHelper factory = cell.getSheet().getWorkbook()
            .getCreationHelper();
    // When the comment box is visible, have it show in a 1x3 space
    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex());
    anchor.setCol2(cell.getColumnIndex() + 1);
    anchor.setRow1(cell.getRowIndex());
    anchor.setRow2(cell.getRowIndex() + 1);
    anchor.setDx1(100);
    anchor.setDx2(100);
    anchor.setDy1(100);
    anchor.setDy2(100);

    // Create the comment and set the text+author
    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString(message);
    comment.setString(str);
    comment.setAuthor("Apache POI");
    // Assign the comment to the cell
    cell.setCellComment(comment);
}