能不能直接连接 excel 表呢,用odbc如何连接呢,他问我要用户名和密码,又说我的文件名没有找到。

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if (filename='') then
      begin
           showmessage('对不起,您没有选择文件!');
      end
      else
      begin
            flag:=0;
            try
                    ExcelApp := CreateOleObject( 'Excel.Application' );
                    //ExcelApp.Visible := True;
                    //ExcelApp.Caption := '应用程序调用 Microsoft Excel';
                    //ExcelApp.WorkBooks.Add;
                    ExcelApp.WorkBooks.Open(filename );
                    count:=excelapp.ActiveSheet.UsedRange.Rows.Count;
                    flag:=1;
                    if MessageDlg('您是否要浏览该项数据?',
                            mtConfirmation, [mbYes,mbNO], 0) = mrYes then
                    begin
                         ExcelApp.Visible := True;
                    end;        except
                    showmessage('无法打开文件!');
            end;
      end;
    end;
      

  2.   

    1.
    Provider=Microsoft.Jet.OLEDB.4.0;
    Data Source=D:\Excel\a.xls;
    Extended Properties=Excel 8.0;//此行自己加上
    2.
    adotable的tabledirect=true;
    选择table1$即可操作.