Search Results for

    Show / Hide Table of Contents

    ExcelFile.ColCount Property

    Number of columns actually used on the active sheet, including formatted columns. You will normally want to use ColCountOnlyData instead.

    Note that this method is slow as it needs to loop over all the rows to find out the biggest used column. Never use it in a loop like "for (int col = 1; col <= xls.ColCount; col++)". Instead try to use ColCountInRow(Int32). If you *need* to use ColCount, cache its value first:

        int RowCount = xls.RowCount;
        int ColCount = xls.ColCount;
        for (int row = 1; row <= RowCount; row++)
        {
            for (int col = 1; col <= ColCount; col++) //It would be faster to use ColCountInRow. See https://doc.tmssoftware.com/flexcel/net/guides/performance-guide.html#avoid-calling-colcount
            {
                DoSomething(row, col);
            }
        }
    

    Remember that loops in C# will evaluate the second parameter every time the loop is executed.

    Syntax

    Namespace: FlexCel.Core

    public abstract Int32 ColCount { get; }

    See also

    • ExcelFile
    In This Article
    Back to top FlexCel Studio for the .NET Framework v7.24.0.0
    © 2002 - 2025 tmssoftware.com