AutofitColumns Method
Changes the width of the columns in the range to achieve the best fit.
Syntax
'Declaration Sub AutofitColumns()
'Usage Dim instance As IRange instance.AutofitColumns()
void AutofitColumns()
Remarks
To know more about resizing rows and columns refer Auto-Fit Rows or Columns. This method is supported on Windows Forms, WPF, ASP.NET, ASP.NET MVC, WinRT, WP, Universal and UWP,Xamarin and NetStandard platforms only.
Example
The following code shows how to auto-size row height to its cell content.
using Syncfusion.XlsIO; class Program { static void Main() { using (ExcelEngine excelEngine = new ExcelEngine()) { //Create worksheet IApplication application = excelEngine.Excel; application.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = application.Workbooks.Create(1); IWorksheet worksheet = workbook.Worksheets[0]; //Auto-fit columns worksheet.Range["B4"].Text = "Fit the content to column"; worksheet.Range["B4"].AutofitColumns(); //Save and dispose workbook.SaveAs("AutoFit.xlsx"); workbook.Close(); excelEngine.Dispose(); } } }
AssemblyVersion
Syncfusion.XlsIO.Base: 16.4460.0.52
See Also