Table of Contents

TXlsFile.Find Method

Finds a value inside a cell and returns the position for the cell, or null if nothing was found.

Syntax

Unit: FlexCel.XlsAdapter

function TXlsFile.Find(const value: TCellValue; const Range: TXlsCellRange; const Start: TCellAddress; const ByRows: Boolean; const CaseInsensitive: Boolean; const SearchInFormulas: Boolean; const WholeCellContents: Boolean): TCellAddress; override;

Parameters

<-> Parameter Type Description
const value TCellValue Value we are searching.
const Range TXlsCellRange Range to Search. Null means the whole worksheet.
const Start TCellAddress Cell where to start searching. For the first time, use null. After this, you can use the result of this method to get the next cell.
const ByRows Boolean If true, the value will be searched down then left. If false, the search will go left then down. SEARCH IS FASTER WHEN BYROWS = FALSE
const CaseInsensitive Boolean If true, string searches will not be case sensitive, "a" = "A"
const SearchInFormulas Boolean If true, the search will cover formulas too.
const WholeCellContents Boolean If true, the string must match the whole cell, not a part of it.

Returns

Cell where the string is found, or null if it is not found.

Examples

To find all cells on a sheet that contain the string "bolts":

var
  Cell: TCellAddress;
...
  Cell := TCellAddress.Empty;  //initialize the value to null to start searching.
  repeat
    Cell := xls.Find('bolts', TXlsCellRange.Null, Cell, false, true, true, false);  //find the next value.
    if Cell.HasValue then
    begin
      LogMessage(Cell.CellRef);
    end;

  until Cell.IsNull; //until it doesn't find any more matches.

See also