Table of Contents

TExcelFile.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(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.Core

property TExcelFile.ColCount: Integer

See also