How to auto adjust column width?

Dear All,


How to auto adjust column width ?

please help

Thanks & Regards



Hi,


Thank you for contacting Aspose support.

You may use Worksheet.AutoFitColumns method for your need. Please check the below provided code snippet for your reference.

C#

var book = new Workbook(myDir + “sample.xlsx”);
var sheet = book.Worksheets[0];
sheet.AutoFitColumns();

Please let us know if you need further assistance.

hi… it does not work


Worksheet sheet = workbook.Worksheets[0];
sheet.Name = REPORTNAME;
sheet.AutoFitColumns();

Hi Winanjaya,


I have tested it with Aspose.Cells for .NET 8.0.0, and found no issue as the above statements are producing desirable results on my end. Please give the latest version a try on your end. In case the problem persists, please provide your sample file for our review because the presented scenario could also be template specific.

Hi


I am using Aspose Cell .NET 8.0.0,
please see generated xls file as enclosed

Hi… it works …


sheet.AutoFitColumns();
workbook.Save(xls);

I put AutoFitColumns before save

Hi,


Good to know that you have figured it out now. 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.