//Delphi中打开Excel文件
var
ExcelApp: Variant; //Excel变量
ExcelFiles: string; //打开的Excel文件名
begin
inherited;
//打开指定的文件
OpenDialog1.InitialDir := ExtractFilePath(ParamStr(0)) + '.\data\';
OpenDialog1.Filter := '*.XLS';
OpenDialog1.Title := '打开Excel文件';
OpenDialog1.FileName := '';
if OpenDialog1.Execute then ExcelFiles := OpenDialog1.FileName else exit;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
ExcelApp.WorkBooks.Open(ExcelFiles);
ExcelApp.WorkSheets[1].Activate;
end;
//取Excel中第i行第一列的值
ExcelApp.Cells[i, 1].Value;
//遍历电子表格
while not (trim(ExcelApp.Cells[i, 1].Value) = '') do
begin
inc(i);
//......
end;