I have a couple of questions about the AutoFitColumn() method.
1. I have a column whose values are generated using a formula. Even though am using the AutoFit method at the end, before saving the worksheet, some values in the column are rendered as “####”. Doesn’t the autofit method take values into consideration? Is there a workaround to ensure the column width is set based on values?
2. The documentation at this page says AutoFit methods are time consuming, is there an alternative method where I can set the width of a column?
I have tested your issue with the following code and it works fine with AutoFitColumn method.
e.g
Workbook workbook = new Workbook(“e:\test2\autofitissue\Sample.xlsx”);
workbook.Worksheets[0].AutoFitColumn(0);
workbook.Save(“e:\test2\autofitissue\outautofitting.xlsx”);
The column is auto-fitted fine.
Yes, if you have long list of data into lots of cells in a column, then it may take more time to auto-fit it. The reason is we have to calculate all the contents and length of the data filled into the cells to subsequently extend the width to fit the longest list based cell in the column. I think you can also try to manually extend the width of the column using Cells.SetColumnWidth() method instead if you got very large list of data.
Moreover, you may try to use the overloaded version accordingly i.e.,:
AutoFitColumn(int columnIndex, int firstRow, int lastRow)
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.