ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

用delphi将EXCEL导入数据库

2021-12-17 10:35:03  阅读:87  来源: 互联网

标签:begin ExcelApp excelx delphi EXCEL excelapp Value 导入 Cells


procedure TForm1.Button1Click(Sender: TObject);

var excelx,excely : string;

begin

try

  ExcelApp := CreateOleObject('Excel.Application');

  WorkBook := ExcelApp.WorkBooks.Open(opendialog.FileName);//使用opendialog对话框指定

//excel档路径

  ExcelApp.Visible := false;

  ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;

  for i := 1 to excelrowcount + 1 do

  begin
    
    excelx := excelapp.Cells[i,1].Value;

    excely := excelapp.Cells[i,2].Value;

    if ((excelapp.Cells[i,1].Value  = '') and (ExcelApp.Cells[i,2].Value = '')) then 

//指定excel档的第 i 行 ,第 1,2(看情况而定)行如果为空就退出,这样的设定,最好是你的档案力这两行//对应数据库中不能为空的数据

      exit

    else

    with query1 do

    begin

      close;
      sql.clear;

sql.add(insert into test(name,address) values(:name,:address));
parambyname(‘name’).asstring := excelx;/

标签:begin,ExcelApp,excelx,delphi,EXCEL,excelapp,Value,导入,Cells
来源: https://blog.csdn.net/xcbzsy/article/details/121990548

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有