Search Results for

    Show / Hide Table of Contents

    Class RangeColumn

    A class that represents a single column of cells.

    Inheritance
    System.Object
    Range
    RangeColumn
    Implements
    System.Collections.Generic.IEnumerable<Cell>
    System.Collections.IEnumerable
    Inherited Members
    Range.ClearContents()
    Range.GetEnumerator()
    Range.ToArray()
    Range.Sum()
    Range.Max()
    Range.Min()
    Range.Avg()
    Range.AddRange(Range)
    Range.AddRange(RangeAddress)
    Range.SubtractRange(Range)
    Range.SubtractRange(RangeAddress)
    Range.RemoveRow(Int32)
    Range.RemoveRow(RangeRow)
    Range.RemoveColumn(String)
    Range.RemoveColumn(Int32)
    Range.RemoveColumn(RangeColumn)
    Range.InsertRow(Int32)
    Range.InsertRows(Int32, Int32)
    Range.InsertColumn(Int32)
    Range.InsertColumn(String)
    Range.InsertColumns(String, Int32)
    Range.InsertColumns(Int32, Int32)
    Range.SortAscending()
    Range.SortDescending()
    Range.SortByColumn(String, SortOrder)
    Range.SortByColumn(Int32, SortOrder)
    Range.Trim()
    Range.ToDataTable(Boolean)
    Range.SetCellValue(Int32, Int32, Object)
    Range.GetValue<TType>()
    Range.TryGetValue<TType>(TType)
    Range.ToString()
    Range.Copy(WorkSheet, String)
    Range.Replace(String, String)
    Range.SaveAsNamedTable(String, Boolean, TableStyle, Boolean)
    Range.SaveAsNamedRange(String, Boolean)
    Range.Row(Int32)
    Range.Column(Int32)
    Range.RangeAddress
    Range.RangeAddressAsString
    Range.Count
    Range.ColumnCount
    Range.RowCount
    Range.Style
    Range.WorkBook
    Range.IsEmpty
    Range.Rows
    Range.Columns
    Range.Value
    Range.FormatString
    Range.Formula
    Range.StringValue
    Range.DateTimeValue
    Range.BoolValue
    Range.IntValue
    Range.DoubleValue
    Range.DecimalValue
    Range.FloatValue
    Range.Int64Value
    Range.LongValue
    Range.Int32Value
    Range.AllRowsInRange
    Range.AllColumnsInRange
    Namespace: IronXL
    Assembly: IronXL.dll
    Syntax
    public class RangeColumn : Range, IEnumerable<Cell>, IEnumerable

    Properties

    ColumnLetter

    Gets the letter anme of the column.

    Declaration
    public string ColumnLetter { get; }
    Property Value
    Type Description
    System.String

    ColumnNumber

    0-based index of the column.

    Declaration
    public int ColumnNumber { get; }
    Property Value
    Type Description
    System.Int32

    Hidden

    Gets or sets a value indicating whether this column is hidden.

    Declaration
    public bool Hidden { get; set; }
    Property Value
    Type Description
    System.Boolean

    Width

    Gets or sets the width of the column.

    Declaration
    public int Width { get; set; }
    Property Value
    Type Description
    System.Int32

    Methods

    AutoSizeColumn()

    Changes width of the column to fit the content based on font measurements.

    This method measures the text in the cell based on the font that is used for the cell.

    If the exact font is not found on the machine, it will try to measure with a default font (Arial).

    ------------------------------------------------

    Usage:

    // Auto-size column B to fit its content
    var workbook = WorkBook.Load("example.xlsx");
    var sheet = workbook.DefaultWorkSheet;
    var column = sheet.GetColumn(1);  // Column B (0-indexed)
    column.AutoSizeColumn();
    workbook.SaveAs("autosized.xlsx");

    ------------------------------------------------

    Declaration
    public void AutoSizeColumn()
    Remarks

    Important Considerations:

    ⚠️ Font Availability: The exact font must be installed on the system for accurate measurements.

    📝 Note: This overload does not consider merged cells. Use AutoSizeColumn(true) to include merged cells.

    Related Documentation:

    📖 How-To Guide:AutoSize Rows and Columns Guide

    📚 API Reference:RangeColumn API Documentation

    Exceptions
    Type Condition
    System.ArgumentException

    Thrown when the column cannot be auto-sized.

    SixLabors.Fonts.FontException

    Thrown when no fonts are found installed on the machine.

    AutoSizeColumn(Boolean)

    Changes width of the column to fit the content based on font measurements.

    This method measures the text in the cell based on the font that is used for the cell.

    If the exact font is not found on the machine, it will try to measure with a default font (Arial).

    ------------------------------------------------

    Usage:

    // Auto-size column B including merged cells
    var workbook = WorkBook.Load("example.xlsx");
    var sheet = workbook.DefaultWorkSheet;
    var column = sheet.GetColumn(1);  // Column B (0-indexed)
    column.AutoSizeColumn(true);  // Include merged cells
    workbook.SaveAs("autosized.xlsx");

    ------------------------------------------------

    Declaration
    public void AutoSizeColumn(bool useMergedCells)
    Parameters
    Type Name Description
    System.Boolean useMergedCells

    If true, the width of merged cells will be taken into account.

    Remarks

    Important Considerations:

    ⚠️ Font Availability: The exact font must be installed on the system for accurate measurements.

    📝 Merged Cells: When useMergedCells is true, the width calculation considers cells that span multiple columns.

    🎯 Long Text: Ensures column width accommodates the longest text content in the column.

    Related Documentation:

    📖 How-To Guide:AutoSize Rows and Columns Guide

    📚 API Reference:RangeColumn API Documentation

    Exceptions
    Type Condition
    System.ArgumentException

    Thrown when the column cannot be auto-sized.

    SixLabors.Fonts.FontException

    Thrown when no fonts are found installed on the machine.

    RemoveColumn()

    Removes the column from the worksheet.

    Declaration
    public void RemoveColumn()

    Implements

    System.Collections.Generic.IEnumerable<>
    System.Collections.IEnumerable

    Inherited members

    ClearContents()
    GetEnumerator()
    ToArray()
    Sum()
    Max()
    Min()
    Avg()
    AddRange(Range)
    AddRange(RangeAddress)
    SubtractRange(Range)
    SubtractRange(RangeAddress)
    RemoveRow(Int32)
    RemoveRow(RangeRow)
    RemoveColumn(String)
    RemoveColumn(Int32)
    RemoveColumn(RangeColumn)
    InsertRow(Int32)
    InsertRows(Int32, Int32)
    InsertColumn(Int32)
    InsertColumn(String)
    InsertColumns(String, Int32)
    InsertColumns(Int32, Int32)
    SortAscending()
    SortDescending()
    SortByColumn(String, SortOrder)
    SortByColumn(Int32, SortOrder)
    Trim()
    ToDataTable(Boolean)
    SetCellValue(Int32, Int32, Object)
    GetValue<TType>()
    TryGetValue<TType>(TType)
    ToString()
    Copy(WorkSheet, String)
    Replace(String, String)
    SaveAsNamedTable(String, Boolean, TableStyle, Boolean)
    SaveAsNamedRange(String, Boolean)
    Row(Int32)
    Column(Int32)
    RangeAddress
    RangeAddressAsString
    Count
    ColumnCount
    RowCount
    Style
    WorkBook
    IsEmpty
    Rows
    Columns
    Value
    FormatString
    Formula
    StringValue
    DateTimeValue
    BoolValue
    IntValue
    DoubleValue
    DecimalValue
    FloatValue
    Int64Value
    LongValue
    Int32Value
    AllRowsInRange
    AllColumnsInRange
    ☀
    ☾
    Downloads
    • Download with Nuget
    • Start for Free
    In This Article
    Back to top
    Install with Nuget
    IronXL_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronXL