Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fit cell size

I'm trying to build an excell file with apache. (HSSFWorkbook)

I cant figure out how to set column width size.

Look at the following example:

enter image description here

The first column (A) has the value: "row number" which we cant see the whole string. The columns (D) and (E) have the same problem, but If we double click on it we can see the full string.

I want to create cells which the user wouldn't need to double click on it. How can I do it ?

like image 884
user3668129 Avatar asked Sep 03 '25 13:09

user3668129


1 Answers

You can use autoSizecolumn() which will set column size based on its header.

sheet.autoSizeColumn(0)// to adjust first column

Please refer this link. It would be helpful...

To set all the available columns , use a for loop

for(int colNum = 0; colNum<row.getLastCellNum();colNum++)   
    workbook.getSheetAt(0).autoSizeColumn(colNum);
like image 173
vembutech Avatar answered Sep 05 '25 16:09

vembutech