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

Free Support Forum - aspose.com

Question about Worksheet.AutoFitColumns()


I’ve noticed that the AutoFitColumns() method does not get columns as narrow as Excel’s auto-fitting. I’d just like to know what the reason(s) for this is/are as of the current version (7.1.1.)


- Matt


You mean to say that AutoFitColumns operation does not work similar to MS Excel. Well, it might extends a column width a bit more to fit the contents in the cells and it might not be 100% accurate as MS Excel but it works fine in most cases. The interesting thing about auto-fitting rows/columns operation is that some users demand that auto-fit rows/columns should be more generous to allow some extra space to fit the data while others require a more reduced /condensed type of auto-fitting rows/columns with minimum space allowed to fit the data. I think we do in the middle of both but satisfy both :)

Do you find any issue regarding auto-fitting columns in the sheet (e.g some cells does not show data completely in the columns). If so, kindly post your template file(s), sample code etc. We will look into it soon.

Thank you.

Thanks for the reply Amjad. I’m not seeing any issue with the way the auto-fitting is currently working; I’m just getting questions from users asking why things aren’t packed in as tightly as possible horizontally.

If it is the case that a little padding is being put in when auto-fitting column(s) to try appease the two camps you mentioned (those who want auto-fit to get things as narrow as possible and those who want auto-fit to leave a little extra room), then would it be possible for Aspose to provide an overload of AutoFitColumns and/or AutoFitColumn in a future release that would allow a developer to specify how much (if any) extra padding they’d like as a parameter?


Thanks for your posting.

Padding actually depends on the type and size of fonts.

Ms-Excel uses Win32 native APIs for graphics, while Aspose.Cells uses .NET framework APIs so minor issues in autofitting will remain.

Being a managed component, Aspose.Cells cannot use Win32 native APIs for graphical metrics, rendering etc.

Anyway, please provide us your sample files, screenshots and sample project replicating the problems, we will look into them and update you asap.


I’m using the AutoFitColumns functionnality and it seems that it doesn’t work as expected with cells using an “Accounting” format.

Here’s my code(see attachments too):
  	    Aspose.Cells.Workbook w = new Aspose.Cells.Workbook(@“c:\temp\book1.xlsx”);
w.Worksheets[0].Cells[“A1”].Value = 80456362.16 ;
w.Worksheets[0].Cells[“A2”].Value = 13489467.16 ;
w.Worksheets[0].Cells[“B1”].Value = DateTime.Now;
w.Worksheets[0].Cells[“C1”].Value = 80456362.16;
w.Worksheets[0].Cells[“C2”].Value = 13489467.16;
w.Worksheets[0].Cells[“D1”].Value = 80456362.16;
w.Worksheets[0].Cells[“D2”].Value = 13489467.16;
w.Save(@“c:\temp\output.xlsx”, Aspose.Cells.SaveFormat.Xlsx);
In the output, you’ll see that the width of the first column is shorter than the content. But for the other columns(c formatted as Number and D formatted as number without 1000 separators) it works as expected.

Best regards,


Hi Laurent,

I can notice the issue as you mentioned. I have run your sample code with your template file but the first column is not auto-fitted properly. I have logged a ticket with an id: CELLSNET-40472. We will look into your issue soon.

Thank you.


We have fixed this issue. Please download and try:
for .NET v7.1.2.1

Thank you.

it works now.

Best regards


Good to know that your issue is sorted out.

Feel free to contact us any time if you need further help or query.

Have a good day!

We updated a project to from - because the hyperlink sorting item we thought was solved in, this is another question later. For now we noticed that the AutoFitColumns does not work like it did in I ran the sample listed above by the user and sure enough it does not appear to be working as it did before. Can you check on this?

I just confirmed that the issue appears to be corrected in 8.1.0, we will go ahead and move up to that for this particular application.

Hi Mark Warner,

Good to know that the latest version fixes your issue.
Sure, we also recommend you to kindly use our latest version (i.e. v8.1.0) because we included many enhancements to Rendering features and Auto-fit functionality.

Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.

I understand that using the latest is typically the best it can also introduce issues that is not easy to resolve.

Thanks for everything.

Hi Mark Warner,

Thanks for your posting and using Aspose.Cells.

Hopefully, you will not encounter any newer issue while upgrading to latest version. In case, you encounter any issue, we will be quick to resolve it. Please feel free to post here if you face any issue or have any other question.