That should work. but
sampleDataSheet.autoSizeColumn(1000000);
automatically extends column 1,000,000.
If you want to automatically expand column 0 (first column), use:
sampleDataSheet.autoSizeColumn(0);
To automatically expand a column from 0 to 9 (first 10 columns):
for (int i=0; i<10; i++){ sampleDataSheet.autoSizeColumn(i); }
In addition, you must create all your rows and fill them with content first before you call autoSizeColumn (so that the column gets the width of the value with the widest width).
(If you want to set the column width to a fixed value, use HSSFSheet.setColumnWidth (int, int) instead.)
Integrating stuff
source share