uses Excel2000;procedure Tfrm_UpdateTblName.btn_OpenClick(Sender: TObject);var iExcelApp: TExcelApplication; // --- Excel Application --- iExcelBook: TExcelWorkbook; // --- Excel WorkBook --- iExcelSheet: TExcelWorksheet; // --- Excel WorkSheet --- sFileName: string; i, j: integer; iRec: integer;begin if dlgOpen1.Execute then begin sFileName := dlgOpen1.FileName; end else begin Exit; end; if not FileExists(sFileName) then begin ShowMessage('文件:' + sFileName + '不存在!'); exit; end; cdsT.EmptyDataSet; iExcelApp := TExcelApplication.Create(nil); iExcelBook := TExcelWorkbook.Create(nil); iExcelSheet := TExcelWorksheet.Create(nil); iExcelApp.Connect; iExcelApp.Visible[0] := False; iExcelBook.ConnectTo(iExcelApp.Workbooks.Open(sFileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0)); iExcelSheet.ConnectTo(iExcelBook.Worksheets.Item[1] as _Worksheet); iExcelSheet.Activate; Application.ProcessMessages; iRec := 0; for i := 2 to 250 do begin if string(iExcelSheet.Cells.item[i, 2]) <> '' then begin cdsT.Append; cdsT.FieldByName('TBL_NAME').AsString := iExcelSheet.Cells.Item[i, 2]; cdsT.FieldByName('TBL_C_NAME').AsString := iExcelSheet.Cells.Item[i, 3]; cdsT.FieldByName('TBL_NOTE').AsString := iExcelSheet.Cells.Item[i, 4]; cdsT.Post; iRec := iRec + 1; //Label1.Caption := '导入:' + IntToStr(iRec); Application.ProcessMessages; end; end; iExcelBook.Close; iExcelApp.Disconnect; iExcelApp.Quit; FreeAndNil(iExcelSheet); FreeAndNil(iExcelBook); FreeAndNil(iExcelApp);end;