We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

AutoFitColumn did not work as expected


I came across some problems when I tried to use the AutoFitColumn function.
The function does change the size (width) of the column, but not enough to display all the data.

Is this because, if the column would have a larger width, it would not fit on one page (A4)?

Is it possible to get set the correct width for the column (so really AutoFitColumn), so that the column is as large as the longest string data in the underlying cells?

Or is it possible to make the row higher, so that there would be more lines of data per row?

I use the following (test) code to set the AutoFitColumn function on the column:

For intColumnIndex As Integer = 0 To objRange.ColumnCount - 1

objRange.Worksheet.Cells(objRange.FirstRow, objRange.FirstColumn + intColumnIndex).Style.IsTextWrapped = False

objRange.Worksheet.AutoFitColumn(objRange.FirstColumn + intColumnIndex)


I have included a picture with how the Excel file looks like after step (so as Excel template / output / how I expected it to be)

I have version of Aspose.Cells


Thanks for considering Aspose.

I think you may wrap the text of those cells in the rows into multiple lines. You may try to extend the row height of those big cells using Cells.SetRowHeight() method and use Cell.Style.IsTextWrapped to true;

Following is my code using a template file which works fine. Attached is the output file.

//Create a Workbook object
Workbook workbook = new Workbook();
//Open the Excel file
//Get the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells["A2"].Style.IsTextWrapped = true;
//Adjust the rows and columns of the sheet.

And we will try to enhnace autofitcolumn method to extend it to accomadate more contents.
Thank you.


Thank you for your tips, and I hope that you can enhance the AutoFitColumn in the future.

With kind regards,

Sjoerd van Loon