Bug 60960 - 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.
Summary: I want create a xls workbook that the sheets are greater than 64 and every sh...
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.12-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-06 13:27 UTC by chengguang
Modified: 2017-05-31 01:39 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.