procedure Tdrkp.Button1Click(Sender: TObject);
var
excelx,excely:string;
excelapp,workbook:olevariant;
excelrowcount,i:integer;
begin
{if (savedialog1.Execute) then
begin
try
lianjie.ADOCon.Close;
lianjie.ADOCon.Provider:='Microsoft.Jet.OLEDB.4.0;Data Source='+SaveDialog1.FileName+';Extended' +
     'Properties="Excel 8.0;HDR=Yes;";Persist Security Info=False' ;
lianjie.ADOCon.Connected:=false ;
lianjie.ADOCon.Connected:=true;
sql:= 'insert into yy01 select * from ' +
    'OpenDataSource(''Microsoft.Jet.OLEDB.4.0'',''Data Source='+SaveDialog1.FileName+';Extended Properties="Excel 5.0;HDR=Yes;";Persist Security Info=False'')...sheet1$' ;
lianjie.ADOCon.Execute(sql);
  Application.MessageBox('导出数据成功  !', PChar('数据导入导出提示'), MB_OK +
    MB_ICONINFORMATION + MB_TOPMOST);
except
 Application.MessageBox('导出数据失败  !', PChar('数据导入导出提示'), MB_OK +
  MB_ICONINFORMATION + MB_TOPMOST);  } try
   ExcelApp := CreateOleObject('Excel.Application');
   workbook:= excelapp.Workbooks.Open(opendialog1.FileName);
   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
    exit
    else
    with lianjie.ado2 do
    begin
    close;
    sql.Clear;
     sql.add('insert into yy01(''登记号码'',''出勤状态'',''对应时间'') values(:登记号码,:出勤状态,:对应时间)');
     Parameters.parambyname('登记号码').value := excelx;
     Parameters.parambyname('出勤状态').value := excelx;
     Parameters.parambyname('对应时间').value := excelx;
     execsql;
     end;
     end;
    finally
    workbook.close;
    excelapp.quit;
    ExcelApp := Unassigned;
    WorkBook := Unassigned;
end;
end;
end.//无效的类别字符!!!

解决方案 »

  1.   

    跟踪一下,看是那一行到那里出问题?for i:=1 to excelrowcount+1 do 想不明白为什么要+1
      

  2.   

    Project   Drive.exe   raised   exception   class   EOleSysError   with   message   '无效的类字符串 '.   Process   stopped.   Use   Step   or   Run   to   continue. 
    try
      ExcelApp := CreateOleObject('Excel.Application');
      workbook:= excelapp.Workbooks.Open(opendialog1.FileName);
      

  3.   

    你的Excel装的有问题,组件没有注册
      

  4.   

    应该是安装的Office版本问题,有一些“精简版”之类的功能不全
      

  5.   

    Parameters.parambyname('登记号码').value := excelx;
    Parameters.parambyname('出勤状态').value := excelx;
    Parameters.parambyname('对应时间').value := excelx;===
    这3个值是设置了一样的值 excelx 
    对应时间              时间类型 
    登记号码,出勤状态    字符类型估计类型不匹配