需用到opendialog、ExcelApplication1、ExcelWorkbook1、ExcelWorksheet1以上均为Delphi自带的组件,另需uses excelxp;单元procedure TForm1.Button1Click(Sender: TObject);//导入excelvar i,j:integer;beginopendialog1.InitialDir:=ExtractFileDir(paramstr(0));//文件的打存放初始路径opendialog1.Execute;TryExcelApplication1.Connect;//EXCEL应用程序ExceptMessageDlg('Excel may not be installed',mtError, [mbOk], 0);Abort;End;ExcelApplication1.Visible[0]:=True;ExcelApplication1.Caption:='Excel Application';try excelapplication1.Workbooks.Open(opendialog1.FileName,null,null,null,null,null,null,null,null,null,null,null,null,0);//打开指定的EXCEL 文件exceptbeginExcelApplication1.Disconnect;//出现异常情况时关闭ExcelApplication1.Quit;showmessage('请选择EXCEL电子表格!');exit;end;end;ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);//ExcelWorkbook1与Eexcelapplication1建立连接ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);//Excelworksheet1与Excelworkbook1建立连接 //开始从EXCEL中取数,放到stringgrid1中,取完数后关闭EXCELfor i:=1 to 1000 do//最大取值1000for j:=1 to 6 dobeginif trim(excelworksheet1.cells.item[i+1,1])<>'' thenbeginstringgrid1.rowCount:=i+1;stringgrid1.Cells[j,i]:=ExcelWorksheet1.Cells.Item[i+1,j];endelsebeginlabel3.caption:=inttostr(i-1);ExcelApplication1.Disconnect;ExcelApplication1.Quit;exit;end;end;end;