这个行的通,参考一下吧。table1 是 DBDemos 下的 animals.dbf
D4 下调试通过。
procedure TForm1.Button2Click(Sender: TObject);
var
ExcelApp,MyWorkBook:Variant;
i :byte;
s: string;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
on Exception do raise exception.Create('无法打开Xls文件,请确认已 经安装EXCEL')
end;
ExcelApp.Visible := true;
ExcelApp.WorkBooks.Open('C:/my documents/book1.xls');
MyworkBook:=ExcelApp.workBooks[1];
for i := 1 to 3 do begin
table1.Append;
table1.fieldbyname('name').AsString := MyWorkBook.WorkSheets[1].Cells[i,2].Value;
table1.fieldbyname('size').Asinteger := MyWorkBook.WorkSheets[1].Cells[i,3].Value;
table1.fieldbyname('weight').AsString := MyWorkBook.WorkSheets[1].Cells[i,4].Value;
table1.post
end;
end;