简单的例子
procedure TForm1.Button1Click(Sender: TObject);
var
ExcelApp,MyWorkBook: OLEVariant;
begin
opendialog1.Filter:='Microsoft Excel Workbook (*.xls)|*.XLS|';
edit2.Text := 'sheet1';
if opendialog1.Execute then
begin
edit1.Text:=opendialog1.FileName;
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已 经安装EXCEL.','',
mb_OK+mb_IconStop);
Exit;
end;
MyworkBook:= ExcelApp.workBooks.Open(opendialog1.FileName);
//打开文件后,对文件进行操作
label1.caption := MyWorkBook.WorkSheets[].Cells[,].Value;
end;
end;