Bug 56852

Summary: add the comment large than 1024, the excel will only display the last 1024 comments
Product: POI Reporter: zhibin fang <silencon>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 3.10-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description zhibin fang 2014-08-14 07:21:06 UTC
hello,

Our project will need to import the excel for some data init. cell will be added the comment about the reasons of error, so there may be add more than 1024 comments, but will only display the last 1024.

e.g.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("mysheet");
HSSFPatriarch p = null;
final Map<HSSFSheet, HSSFPatriarch> drawings = new HashMap<HSSFSheet, HSSFPatriarch>();
if(drawings.containsKey(sheet)) {
  p = drawings.get(sheet);
} else {
  p = sheet.createDrawingPatriarch();
}
for (int i = 0; i < 2000; i++) {
  HSSFCell cell = sheet.createRow(i).createCell(1);
  cell.setCellValue(new HSSFRichTextString("comment" + i));
  HSSFAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, i, (short) 3, i + 3);
  HSSFComment comment = p.createComment(anchor);
  comment.setAuthor("fzb");
  comment.setString(new HSSFRichTextString("add the comment" + i + "success!"));
  cell.setCellComment(comment);
}
		
FileOutputStream out = new FileOutputStream("writerPostil.xls");
wb.write(out);

Regards
Comment 1 zhibin fang 2014-08-21 07:45:04 UTC
i fixed this problem.
Comment 2 Darren Roberts 2014-08-22 08:29:53 UTC
Would you mind creating a patch or sharing how you fixed the problem please? 

This issue has come up a few times and since I also need more than 1024 comments in my project it would be good for it to be fixed once and for all.
Comment 3 zhibin fang 2014-10-16 02:25:28 UTC
(In reply to Darren Roberts from comment #2)
> Would you mind creating a patch or sharing how you fixed the problem please? 
> 
> This issue has come up a few times and since I also need more than 1024
> comments in my project it would be good for it to be fixed once and for all.

the class HSSFShape HSSFShapeGroup HSSFComment will set the shape id through the setSharpId method, the setSharpId value is sharpId % 1024, this is the problem.
HSSFPatriarch's createCellComment method will call the class EscherAggregate's addTailRecord method finally.
the addTailRecord is:
tailRec.put(note.getShapeId(), note);
the tailRec is the LinkedHashMap<Integer, NoteRecord> object.

the type of map key is Integer. the key's value is note.getShapeId().

the key --> sharpId % 1024 --> the value of key will be repeated.

the size of the tailRec is 1024 forever.

this is the point of the problem.
Comment 4 Dominik Stadler 2015-03-11 20:07:37 UTC
This and bug 55275 actually handle the same thing as far as I see.

*** This bug has been marked as a duplicate of bug 55275 ***