Search Results for

    Show / Hide Table of Contents

    TXlsFile.ColCount Property

    Number of columns actually used on the active sheet, including formatted columns. You will normally want to use TExcelFile.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 TExcelFile.ColCountInRow(Integer). If you *need* to use ColCount, cache its value first:

    var
      RowCount: Int32;
      ColCount: Int32;
      row: Int32;
      col: Int32;
    ...
      RowCount := xls.RowCount;
      ColCount := xls.ColCount;
      for row := 1 to RowCount do
      begin
        for col := 1 to ColCount do  //It would be faster to use ColCountInRow. See https://doc.tmssoftware.com/flexcel/vcl/guides/performance-guide.html#avoid-calling-colcount
        begin
          DoSomething(row, col);
        end;
      end;
    

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

    Syntax

    Unit: FlexCel.XlsAdapter

    property TXlsFile.ColCount: Integer

    See also

    • TXlsFile
    In This Article
    Back to top FlexCel Studio for VCL and FireMonkey v7.24
    © 2002 - 2025 tmssoftware.com