Search Results for

    Show / Hide Table of Contents

    TExcelFile.ColCountInRow Method

    Overloads

    • TExcelFile.ColCountInRow(Integer)
    • TExcelFile.ColCountInRow(Integer, Integer)

    TExcelFile.ColCountInRow(Integer)

    This method returns the NOT EMPTY cells on ONE ROW.

    Note that this is not the full column count, but only the count of those columns that have any data on them for the given row. So for example if in row 2 you have a value in A2 and another in E2, ColCountInRow(2) will return 2 (cells A2 and E2), not 5 (columns from A to E).

    You can use this together with ColFromIndex(Integer, Integer) and ColToIndex(Integer, Integer) to iterate faster on a block, skipping all empty cells.

    Syntax

    Unit: FlexCel.Core

    function TExcelFile.ColCountInRow(const row: Integer): Integer; overload; virtual; abstract;

    Parameters

    <-> Parameter Type Description
    const row Integer Row index. (1-based)

    Returns

    The number of existing columns on one row.

    Examples

    Instead of writing:

    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;
    

    You can use:

    var
      RowCount: Int32;
      row: Int32;
      ColCountInRow: Int32;
      colIndex: Int32;
    ...
      RowCount := xls.RowCount;
      for row := 1 to RowCount do
      begin
        ColCountInRow := xls.ColCountInRow(row);
        for colIndex := 1 to ColCountInRow do
        begin
          DoSomething(row, xls.ColFromIndex(row, colIndex));
        end;
    
      end;
    

    See also

    • TExcelFile
    • ColFromIndex(Integer, Integer)
    • ColToIndex(Integer, Integer)
    • LoopOverUsedRange

    TExcelFile.ColCountInRow(Integer, Integer)

    This method returns the NOT EMPTY cells on ONE ROW, for a given sheet.

    Note that this is not the full column count, but only the count of those columns that have any data on them for the given row. So for example if in row 2 you have a value in A2 and another in E2, ColCountInRow(2) will return 2 (cells A2 and E2), not 5 (columns from A to E).

    You can use this together with ColFromIndex(Integer, Integer) and ColToIndex(Integer, Integer) to iterate faster on a block, skipping all empty cells. Or you can call LoopOverUsedRange for a method that does the looping for you using those methods.

    Syntax

    Unit: FlexCel.Core

    function TExcelFile.ColCountInRow(const sheet: Integer; const row: Integer): Integer; overload; virtual; abstract;

    Parameters

    <-> Parameter Type Description
    const sheet Integer Sheet where we are working. It might be different from ActiveSheet.
    const row Integer Row index. (1-based)

    Returns

    The number of existing columns on one row.

    Examples

    Instead of writing:

    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;
    

    You can use:

    var
      RowCount: Int32;
      row: Int32;
      ColCountInRow: Int32;
      colIndex: Int32;
    ...
      RowCount := xls.RowCount;
      for row := 1 to RowCount do
      begin
        ColCountInRow := xls.ColCountInRow(row);
        for colIndex := 1 to ColCountInRow do
        begin
          DoSomething(row, xls.ColFromIndex(row, colIndex));
        end;
    
      end;
    

    See also

    • TExcelFile
    • ColFromIndex(Integer, Integer)
    • ColToIndex(Integer, Integer)
    • LoopOverUsedRange
    In This Article
    Back to top FlexCel Studio for VCL and FireMonkey v7.24
    © 2002 - 2025 tmssoftware.com