我用以下代码从数据库中的表向导数据(此代码是经过CSDN上的一位大侠指点后得出的)
var
 xlsapp,xlssheet:variant;
 i,j:integer;
begin
 try
  if varisempty(xlsapp) then
   xlsapp:=createoleobject('excel.application');
  xlsapp.workbooks.add;
  xlssheet:=xlsapp.worksheets['sheet1'];
 except
  application.MessageBox('不能打EXCEL',pchar('警告'),mb_ok);
  abort;
 end;
 for j:=0 to rdt.FieldCount-1 do
 begin
  xlssheet.cells[2,j+1]:=rdt.Fields[j].FieldName;
 end;
 with rdt do
 begin
  first;
  for i:=0 to recordcount-1 do
  begin
   for j:=0 to fieldcount-1 do
   begin
    xlssheet.cells[i+3,j+1]:=fields[j].AsString;
   end;
   next;
  end;
 end;
 xlsapp.visible:=true;

解决方案 »

  1.   

    提问者的要求是不直接打开excel而通过数据引擎传递数据,关注
      

  2.   

    先给你一个列子:
    ADOConnection的Extended Properties:
    Extended Properties=Excel 8.0
    注意ADOTABLE的:
        TableDirect = True
    其次:
    在ADOQuery中 select * From [Sheet1$]就可以将对应的表的内容读出
    记住一定要在表名两边加[]在表名后面加$,不然就报FROM 子句的语法错误
    在ADOTable中选择表名时也应手工将这两个符号加上object Form1: TForm1
      Left = 192
      Top = 168
      Width = 544
      Height = 375
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object DBGrid1: TDBGrid
        Left = 48
        Top = 200
        Width = 320
        Height = 120
        DataSource = DataSource1
        TabOrder = 0
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -11
        TitleFont.Name = 'MS Sans Serif'
        TitleFont.Style = []
      end
      object ADOConnection1: TADOConnection
        Connected = True
        ConnectionString = 
          'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\delphi\Applicati' +
          'on\通讯1.xls;Extended Properties=Excel 8.0;Persist Security Info=F' +
          'alse'
        LoginPrompt = False
        Mode = cmShareDenyNone
        Provider = 'Microsoft.Jet.OLEDB.4.0'
        Left = 160
        Top = 72
      end
      object ADOTable1: TADOTable
        Active = True
        Connection = ADOConnection1
        CursorType = ctStatic
        TableDirect = True
        TableName = 'Sheet1$'
        Left = 248
        Top = 144
      end
      object DataSource1: TDataSource
        DataSet = ADOTable1
        Left = 120
        Top = 88
      end
    end
      

  3.   

    我想用SQL语句去实现,而不是手工去操作
    我相信MS会有一些内部的存储过程调用实现,但不知道怎么入手 
      

  4.   

    老大,您是真不明白,假不明白。
    真失败。让别人明白,真是一件很难的事情。
    用ADO连接上以后,您老就可以直接用SQL来访问来呀?
    !!!!
    select * From [Sheet1$]