Syncfusion.XlsIO.Base
Example 


One-based column index.

AutofitColumn Method

Changes the width of the specified column to achieve the best fit.
Syntax
'Declaration
 
Sub AutofitColumn( _
   ByVal colIndex As Integer _
) 
'Usage
 
Dim instance As IWorksheet
Dim colIndex As Integer
 
instance.AutofitColumn(colIndex)
void AutofitColumn( 
   int colIndex
)

Parameters

colIndex
One-based column index.
Example
The following code illustrates how to Auto-fit the column.
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];
            
            //Set text
            worksheet["A1"].Text = "Sample text in cell";
            
            //Set auto fit
            worksheet.AutofitColumn(1);
            
            //Save and dispose
            workbook.SaveAs("CellFormats.xlsx");
            workbook.Close(); 
        }
    }
}
AssemblyVersion

Syncfusion.XlsIO.Base: 16.4460.0.40

See Also