This project is read-only.

Excel AutoSizeColumn

Aug 5, 2009 at 8:00 AM


This method 'AutoSizeColumn(ColumnIndex)'  doesn't work...

It resizes the columns but not properly.

NPOI Version 1.2.1.


for (int i = this.SheetNumber; i >= 0; i--)
                int indexCell = 0;
                HSSFCell headerCellToAutoSize = this._ExcelDocument.GetSheetAt(i).GetRow(0).GetCell(indexCell);
                while (headerCellToAutoSize != null)
                    headerCellToAutoSize = this._ExcelDocument.GetSheetAt(i).GetRow(0).GetCell(indexCell);



Aug 11, 2009 at 2:21 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 1, 2010 at 2:50 PM
Edited Jun 2, 2010 at 12:44 PM

I've found that the following doesn't work, at least not consistently, with v1.2.2. The 1st 2-columns are getting set, but not the last one. At the point where this snippet is executed, the entire worksheet has been populated, and the cell style and font for row #0, containing the column titles, has been set. When I open the the file with Excel and manually set the column to AutoFit, it adds 15-pixels to the width of the column; from 112-pixels to 127.

      IEnumerator columns = ws.GetRow(0).GetCellEnumerator();
      while (columns.MoveNext())
        HSSFCell column = (HSSFCell)columns.Current;