apache poi excel big auto column width

后端 未结 3 927
清歌不尽
清歌不尽 2021-01-04 05:57

I am try to create a big excel 2010 with 30 columns and 1 million records with Apache poi latest. I am creating as describe in this link http://svn.apache.org/repos/asf/poi

相关标签:
3条回答
  • 2021-01-04 06:26

    First Select the first row or header because only Header can give you the max number of cells in a row.

    HSSFRow row = wb.getSheetAt(0).getRow(0);
    

    Then use autoSizeColumn on each column of that row

    for(int colNum = 0; colNum<row.getLastCellNum();colNum++)   
        wb.getSheetAt(0).autoSizeColumn(colNum);
    

    This will set the column width same as that of its Header width.

    0 讨论(0)
  • 2021-01-04 06:34

    sheet.autoSizeColumn(columnNumber) works. this will resize the column to the largest cell length.

    0 讨论(0)
  • 2021-01-04 06:36

    I would also suggest you look at using sxssf. It uses an xml format to load it into Excel. This is much faster and a better way to create large reports or grids. The autosizing function in xssf takes too long by default.

    0 讨论(0)
提交回复
热议问题