Bug 60960

Summary: I want create a xls workbook that the sheets are greater than 64 and every sheet have comment, but it not work at the version 3.12 and later version.
Product: POI Reporter: chengguang <ben.zou>
Component: HSSFAssignee: POI Developers List <dev>
Status: NEEDINFO ---    
Severity: normal    
Priority: P2    
Version: 3.12-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description chengguang 2017-04-06 13:27:43 UTC
I want create a xls workbook that the sheets number are greater than 64 and every sheet has comment, it work at the version 3.10, but it not work at 3.12 and later version. The following code is my test code. The first 63 sheets is ok, but when the sheets are greater than 64 , it throw the exception "The exception is Cannot add more than 65535 shapes. "

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) {
    HSSFWorkbook wb = new HSSFWorkbook();
    for (int i = 0; i < 256; i++) {
      HSSFSheet sheet = wb.createSheet("Cell comments in POI HSSF" + (i + 1));
      // Create the drawing patriarch. This is the top level container for all shapes including cell comments.
      HSSFPatriarch patr = sheet.createDrawingPatriarch();
      try {
        //create a cell in row 3
        HSSFCell cell = sheet.createRow(0).createCell(0);
        cell.setCellValue(new HSSFRichTextString("Hello, World"));
        //anchor defines size and position of the comment in worksheet
        HSSFComment comment = patr.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short) 1,  1, (short) 6, 4));
        // set text in the comment
        comment.setString(new HSSFRichTextString("We can set comments in POI" + 0));
        //set comment author.
        //you can see it in the status bar when moving mouse over the commented cell
        comment.setAuthor("Apache Software Foundation");
        // The first way to assign comment to a cell is via HSSFCell.setCellComment method
        cell.setCellComment(comment);
      } catch (Exception e) {
        System.out.printf("Add comment fail at sheet%d. The exception is %s%n", i+1, e.getMessage());
      }
    }
    try (FileOutputStream out = new FileOutputStream("poi_comment.xls")) {
      wb.write(out);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
Comment 1 Dominik Stadler 2017-05-29 20:12:10 UTC
The HSSF-format (i.e. .xls) is limited in some ways, have you tried using the XSSF-classes (.xlsx)?
Comment 2 chengguang 2017-05-31 01:39:33 UTC
(In reply to Dominik Stadler from comment #1)
> The HSSF-format (i.e. .xls) is limited in some ways, have you tried using
> the XSSF-classes (.xlsx)?

The xssf-classed is ok. The Hssf-format have the problem. But why it work ok at the version 3.10, and it not work at 3.12 and later version.