Table of Contents

ExcelFile.LoopOverUsedRange Method

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

Syntax

Namespace: FlexCel.Core

public void LoopOverUsedRange(TXlsCellRange aRange, Action<TLoopOverUsedRangeParameters> reader)

Parameters

<-> Parameter Type Description
aRange TXlsCellRange Range where we want to extract the cell values.
reader Action<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:

    object[,] GetRangeAsArray(ExcelFile xls, TXlsCellRange range)
    {
        object[,] Result = new object[range.RowCount, range.ColCount];
        xls.LoopOverUsedRange(range, (x) =>
        {
            Result[x.Row - range.Top, x.Col - range.Left] = x.Value;
        });
        return Result;
    }

See also