Xceed Workbooks for .NET v3.0 Documentation
Xceed.Workbooks.NET Assembly / Xceed.Workbooks.NET Namespace / Column Class / AutoFit Method

The minimum desired Width when autoFitting a Column.

The default value is 0.

The maximum desired Width when autofitting a Column.

The default value is 255.

The Id for the Row from where to start calculating the width of the Cells' content. 

The default value is 0 (the first RowId in a Column).

The Id for the Row from where to stop calculating the width of the Cells' content.

The default value is 1048575 (the last RowId in a Column).

Example


In This Topic
    AutoFit Method (Column)
    In This Topic
    Adjusts the Column's Width based on the Cell with the widest content.
    Syntax
    'Declaration
     
    
    Public Overrides Sub AutoFit( _
       Optional ByVal minimumWidth As Double, _
       Optional ByVal maximumWidth As Double, _
       Optional ByVal startRowId As Integer, _
       Optional ByVal endRowId As Integer _
    ) 
    'Usage
     
    
    Dim instance As Column
    Dim minimumWidth As Double
    Dim maximumWidth As Double
    Dim startRowId As Integer
    Dim endRowId As Integer
     
    instance.AutoFit(minimumWidth, maximumWidth, startRowId, endRowId)
    public override void AutoFit( 
       double minimumWidth,
       double maximumWidth,
       int startRowId,
       int endRowId
    )

    Parameters

    minimumWidth

    The minimum desired Width when autoFitting a Column.

    The default value is 0.

    maximumWidth

    The maximum desired Width when autofitting a Column.

    The default value is 255.

    startRowId

    The Id for the Row from where to start calculating the width of the Cells' content. 

    The default value is 0 (the first RowId in a Column).

    endRowId

    The Id for the Row from where to stop calculating the width of the Cells' content.

    The default value is 1048575 (the last RowId in a Column).

    Example
    using( var workbook = Workbook.Create( "test.xlsx" ) )
      {
        // Get the first worksheet. A workbook contains at least 1 worksheet.
        var worksheet = workbook.Worksheets[ 0 ];
    
        worksheet.Cells[ "D6" ].Value = "This column has an autoFit.";
        worksheet.Columns[ "D" ].AutoFit();
    
        // Save workbook to disk.
        workbook.Save();
      }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also