HotXLS-documentatie

ForEachCell methode

Somt de geladen cellen in een klassiek XLS-werkblad op en roept een toepassingscallback aan voor elke cel

Syntaxis

type
  TXLSCellReadEvent = procedure(
    Sender: TObject;
    SheetIndex, Row, Col: Integer;
    const Value: Variant;
    const Formula: WideString;
    var Cancel: Boolean) of object;

function ForEachCell(Callback: TXLSCellReadEvent): Integer;

Opmerkingen

ForEachCell walks only cells that exist in the loaded worksheet model. It does not scan every possible row en column in the sheet
Cells are visited in row-major order. SheetIndex, Row, en Col are 1-based public coordinates. Value is the current cell value. Formula contains the formula text for formula cells en is empty for ordinary value cells
Stel Cancel in op True in de callback om de scan vroegtijdig af te breken. De retourwaarde is het aantal uitgevoerde callbacks

Voorbeeld

procedure TForm1.ReadCell(Sender: TObject; SheetIndex, Row, Col: Integer;
  const Value: Variant; const Formula: WideString;
  var Cancel: Boolean);
begin
  Memo1.Lines.Add(Format('%d:%d = %s', [Row, Col, VarToStr(Value)]));
  if Row >= 1000 then
    Cancel := True;
end;

Visited := Workbook.Sheets[1].ForEachCell(ReadCell);

Zie Ook