JAVA+POI API Excel- Need to increase width of the column

This should work. However,

sampleDataSheet.autoSizeColumn(1000000);

auto-expands column 1000000.

If you want to auto-expand column 0(the first column), use:

sampleDataSheet.autoSizeColumn(0);

To auto-expand column 0 to 9(the first 10 columns):

for (int i=0; i<10; i++){
   sampleDataSheet.autoSizeColumn(i);
}

Also, you should create all your rows and fill them with content first, before you call autoSizeColumn(so the column gets the width of the value with the broadest width).

(If you want to set the column width to a fixed value, use HSSFSheet.setColumnWidth(int,int) instead.)


// We can set column width for each cell in the sheet        
sheet.setColumnWidth(0, 1000);
sheet.setColumnWidth(1, 7500);
sheet.setColumnWidth(2, 7500);

// By applying style for cells we can see the total text in the cell for specified width
HSSFCellStyle cellStyle = workBook.createCellStyle();
cell.setCellStyle(cellStyle );
cellStyle.setWrapText(true);