列舉傳統 XLS 工作表中已載入的儲存格,並對每個儲存格呼叫應用程式回呼
語法
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 僅遍歷已載入工作表模型中存在的儲存格。它不會掃描工作表中每個可能的列和欄
儲存格以列優先順序存取。SheetIndex、Row 和 Col 為 1 起始的公開座標。Value 為目前儲存格的值。Formula 包含公式儲存格的公式文字,對普通值儲存格則為空白
在回呼中將 Cancel 設為 True 可提前停止掃描。傳回值為回呼的呼叫次數
範例
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);
另請參閱