poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60960] New: 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.
Date Thu, 06 Apr 2017 13:27:43 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60960

            Bug ID: 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
           Version: 3.12-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: ben.zou@huawei.com
  Target Milestone: ---

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();
    }
  }
}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message