1

I am using BigGridDemo example for POI since I have to generate excel with a million records. However, I am unable to set the column width in the template.

https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java

I tried this:

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet("Big Grid");

//sheet.autoSizeColumn(0);
sheet.setColumnWidth(0, 13);

It somehow does not pick up the formatting from the template.xlsx

In case anyone is familiar with BigGridDemo, please help!

Thanks!

user1797559
  • 77
  • 1
  • 9

2 Answers2

0

You shouldn't be using the BigGridDemo any more! As the name suggests, it was a demo of a possible way to handle low memory writing of big .xlsx files

Instead, you should be using SXSSF. SXSSF implements the ideas of the BigGrid Demo, but provides the standard POI SpreadSheet interface to do so, and implements more of the format. You can see the SXSSF section of the site for the current restrictions on what isn't supported.

Gagravarr
  • 47,320
  • 10
  • 111
  • 156
  • 1
    But SXSSF does not support progressive write of workbook to the (servlet) output stream. It writes workbook at once via [workbook.write()](https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFWorkbook.html#write(java.io.OutputStream)). – lu_ko May 07 '15 at 11:58
  • The BigGridDemo doesn't/didn't support progressive writing either. Not sure what you'd gain from it anyway - you need to wait until you've finished populating the sheets before you can finalise various references needed for a valid file – Gagravarr May 07 '15 at 12:14
  • So there is no chance to write XLSX file row by row as CSV/Text file? I'm pointing to this answer: http://stackoverflow.com/a/3076312/3271406 – lu_ko May 07 '15 at 12:27
  • Nope, if you want line-by-line, use CSV. Excel has back-and-forth references between bits of the file. You can generate parts of it in a streaming way, which is what SXSSF does, but the overall file can't be – Gagravarr May 07 '15 at 13:43
0

You should try a bigger number than 13. Try 5000 for example. See api reference for details setColumnWidth()

BenMorel
  • 34,448
  • 50
  • 182
  • 322
artmaro
  • 21
  • 4