本文整理自网络,侵删。
uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);const ESatir = $0000000B;var Adet: Integer; Book: Variant; SSay, j, I: Integer; Excel, Sheet: Variant;begin Adet := 0;
OpenDialog.Filter := 'Excel *.xls,*.xlsx|*.xls;*.xlsx'; OpenDialog.Options := OpenDialog.Options + [ofAllowMultiSelect]; if OpenDialog.Execute then begin for I := 0 to OpenDialog.Files.Count - 1 do begin Excel := CreateOleObject('Excel.Application'); Book := Excel.WorkBooks.Open(OpenDialog.Files[I]); Sheet := Book.WorkSheets['Master']; // Sayfa ad? SSay := Excel.ActiveSheet.Cells.SpecialCells(ESatir, EmptyParam).Row; try With FDQuery do begin for j := 5 to SSay do begin Inc(Adet); Close; SQL.Clear; SQL.Add('Insert Into LIST (SIRANO, GIRIS, IDADI, URUN)'); SQL.Add(' Values (:SR, :GR, :IA, :UR)'); ParamByName('SR').AsInteger := Adet; ParamByName('GR').Value := Sheet.Cells[j, 2].Text; ParamByName('IA').Value := Sheet.Cells[j, 3].Text; ParamByName('UR').Value := Sheet.Cells[j, 4].Text; ExecSQL;Application.ProcessMessages; end; end; finally Screen.Cursor := crDefault; Excel.WorkBooks.Close; Excel.Quit; Excel := Unassigned; Sheet := Unassigned; end; end; end; FDQuery.Close;
end;
end;
相关阅读 >>
Delphi使用tclientdataset时不携带midas.dll的方法
Delphi tnotification android通知
老外写的在桌面添加快捷方式(Delphi xe5 android)
idhttp相关:伪造来源地址、cookie欺骗、通过代理访问
更多相关阅读请进入《Delphi》频道 >>