2014-09-10 53 views
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); 

那裏有什麼問題?我知道你必須創建繪圖只有一次,但我沒有交叉...

+0

哪您使用的POI版本是否使用'HSSF'或'XSSF'?乍一看,我可以看到你的代碼沒有問題。我使用類似的代碼來創建幾十條評論,並且沒有問題。必要的步驟都在那裏。重複使用'Drawing'和'CreationHelper'也不是問題。 – 2014-09-10 14:25:45

+0

您是否在'createDrawingPatriarch()'WRT中僅看到過一次這樣的警告,以及它如何將HSSF中的任何圖紙/註釋都放入工作表中? – Gagravarr 2014-09-10 15:32:10

+0

2塞巴斯蒂安。我使用3.10-FINAL。我正在使用XSSF(SXSSFWorkbook)。 – kosta5 2014-09-11 10:54:39

回答

2

因此,事實證明,當使用SXSSF你不能使用評論(你不應該我猜)。您只能添加一個在電子表格中有效的評論,這是有用的。

詳情請參看POI文件表位於: poi.apache.org/spreadsheet - >它說在那裏了SXSSF 評論 - >無(好,我證明,你可以有1條評論:))