เอกสาร HotXLS

เมธอด ForEachCell

ระบุเซลล์ที่โหลดแล้วใน worksheet XLS แบบคลาสสิกและเรียก callback ของแอปพลิเคชันสำหรับแต่ละเซลล์

ไวยากรณ์

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;

หมายเหตุ

ForEachCell เดินเฉพาะเซลล์ที่มีอยู่ในโมเดล worksheet ที่โหลดแล้ว ไม่สแกนทุกแถวและคอลัมน์ที่เป็นไปได้ในแผ่น
เซลล์จะถูกเยี่ยมชมตามลำดับแถว-หลัก SheetIndex, Row และ Col เป็นพิกัดสาธารณะฐาน 1 Value คือค่าเซลล์ปัจจุบัน Formula มีข้อความสูตรสำหรับเซลล์สูตรและว่างเปล่าสำหรับเซลล์ค่าปกติ
กำหนด Cancel เป็น True ใน callback เพื่อหยุดการสแกนก่อนกำหนด ค่าที่คืนคือจำนวน callback ที่เรียกใช้

ตัวอย่าง

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);

ดูเพิ่มเติม