Auto Fit Column width in Excel worksheet cells according to data is not working in Java

HI Team,


I have tried the below to increase the column width as per data.Still i am unable to do it .Please suggest.Please refer attahced Excel file which is getting generated.Name column width is not set properly.we would like to apply the wrap after set column width.


code 1:
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();

//============== Setting Row Height ==============
//Setting the height of the second row to 40
cells.setRowHeight(1, 40);

//Setting the height of all rows in the worksheet to 15
[//worksheet.getCells ](https://worksheet.getcells/)().setStandardHeight(15f);

//============== Setting Column Width ============
//Setting the width of the second column to 17.5
cells.setColumnWidth(1, 50);

Code 2:

worksheet.autoFitColumns();

Please provide any sample code if you have any.



Hi Chiranjeevi,


Thank you for contacting Aspose support.

We have evaluated the presented scenario while using the latest version of Aspose.Cells for Java 8.3.1, and we are unable to notice any problem with the column widths. The following piece of code works perfectly to extends the column widths according to the text length. We would request you to please download the latest version (links shared above) and give it a try on your end.

Java

Workbook wb = new Workbook(“test.xlsx”);
wb.getWorksheets().get(0).autoFitColumns();
wb.save(“output.xlsx”, SaveFormat.XLSX);