Search Results for

    Show / Hide Table of Contents

    TExcelFile.LoopOverUsedRange Method

    This method loops over a range of cells, and calls an action for every cell that has data.

    Syntax

    Unit: FlexCel.Core

    procedure TExcelFile.LoopOverUsedRange(const aRange: TXlsCellRange; const reader: TProc<TLoopOverUsedRangeParameters>);

    Parameters

    <-> Parameter Type Description
    const aRange TXlsCellRange Range where we want to extract the cell values.
    const reader TProc<TLoopOverUsed​Range​Parameters> Anonymous method that will be called once for each cell with a value inside the range.

    Examples

    To fill an array with all the cells in a range, you could use:

    function GetRangeAsArray(const xls: TExcelFile; const range: TXlsCellRange): TCellValueArray2;
    var
      //We can't capture Result in an anonymous method.
      //So we will use a temporary ResultArray variable.
      ResultArray: TCellValueArray2;
    begin
      ResultArray := nil;
      SetLength(ResultArray, range.RowCount, range.ColCount);
      xls.LoopOverUsedRange(range, 
        procedure (x: TLoopOverUsedRangeParameters)
        begin
          ResultArray[x.Row - range.Top, x.Col - range.Left] := x.Value;
        end);
    
      exit (ResultArray);
    end;
    

    See also

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