0
我想分配多個註釋到多個單元格。當打開文件excel抱怨說「Excel發現不可讀的內容...你想恢復這個工作簿的內容嗎?」多個評論apache poi
當我只有一個評論它的作品,2個或更多評論失敗。看到我的代碼如下:
String oper = "OPERATION TO DO AFTER UPLOAD";
Cell c = row.createCell(0);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(oper);
c.setCellStyle(headerStyle);
CreationHelper factory = wb.getCreationHelper();
Drawing drawing = sh.createDrawingPatriarch();
//comment for operation
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(c.getColumnIndex());
anchor.setCol2(c.getColumnIndex()+1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum()+3);
Comment comment = drawing.createCellComment(anchor);
RichTextString str = factory.createRichTextString("Please note that UPDATE will translate to INSERT (if ENTITY_ID column is empty) or UPDATE (if ENTITY_ID column is a number)");
comment.setString(str);
comment.setAuthor("me");
// Assign the comment to the cell
c.setCellComment(comment);
String entity_id = "ENTITY ID";
c = row.createCell(1);
c.setCellType(Cell.CELL_TYPE_STRING);
c.setCellValue(entity_id);
c.setCellStyle(headerStyle);
// comment for EntityID
ClientAnchor anchorEid = factory.createClientAnchor();
anchorEid.setCol1(c.getColumnIndex());
anchorEid.setCol2(c.getColumnIndex() + 1);
anchorEid.setRow1(row.getRowNum());
anchorEid.setRow2(row.getRowNum() + 3);
Comment commentEid = drawing.createCellComment(anchorEid);
RichTextString strEid = factory
.createRichTextString("Please note that UPDATE will translate to INSERT (if ENTITY_ID column is empty) or UPDATE (if ENTITY_ID column is a number)");
commentEid.setString(strEid);
commentEid.setAuthor("me");
// Assign the comment to the cell
c.setCellComment(commentEid);
那裏有什麼問題?我知道你必須創建繪圖只有一次,但我沒有交叉...
哪您使用的POI版本是否使用'HSSF'或'XSSF'?乍一看,我可以看到你的代碼沒有問題。我使用類似的代碼來創建幾十條評論,並且沒有問題。必要的步驟都在那裏。重複使用'Drawing'和'CreationHelper'也不是問題。 – 2014-09-10 14:25:45
您是否在'createDrawingPatriarch()'WRT中僅看到過一次這樣的警告,以及它如何將HSSF中的任何圖紙/註釋都放入工作表中? – Gagravarr 2014-09-10 15:32:10
2塞巴斯蒂安。我使用3.10-FINAL。我正在使用XSSF(SXSSFWorkbook)。 – kosta5 2014-09-11 10:54:39