请问Delphi怎样从Excel中提取数据?

解决方案 »

  1.   

    procedure TForm14.SpeedButton6Click(Sender: TObject);
    var 
    MSExcel: Variant; 
    i,j: Integer;
    begin
    OpenDialog1.Filter:='*.XLS|*.XLS';
    OpenDialog1.DefaultExt:='XLS'; 
    if OpenDialog1.Execute then 
    begin 
      MSExcel:=CreateOLEObject('Excel.Application');
      MSExcel.WorkBooks.Open(OpenDialog1.FileName);
      MSExcel.Visible:=False;
      stringgrid1.RowCount:=Msexcel.activesheet.usedrange.rows.count;
      //从有数据的行逐行读入数据 
      for i:=1 to MSExcel.ActiveSheet.UsedRange.Rows.Count do
       for j:=1 to 15 do
      begin
       stringgrid1.Cells[i,j]:=MSExcel.Cells[i,j].Value;
      end;
      MSExcel.ActiveWorkBook.Close;
      MSExcel.Quit; 
    end; 
    end; 
    你参考一下
      

  2.   

    1 ado,将adoconnection的connecionstring:='Provider=MSDASQL.1;Persist Security Info=False;Extended Properties="DSN=Excel Files;DBQ=C:\Documents and Settings\jj\My Documents\阈值说明.xls;DefaultDir=C:\Documents and Settings\jj\My Documents;DriverId=790;MaxBufferSize=2048;PageTimeout=5;"'
    2 用ole调用
    eclApp := CreateOleObject('Excel.Application');

    Microsoft OLE DB Provider for SQL Server 错误 '80040e31' 超时已过期 /Expert/reply.asp,行105
      

  3.   

    你们的OlE Object是指Servers页上的关于Excel的控件吗?
      

  4.   

    ExpInfoOle.DestroyObject;
      ExpInfoOle.CreateObjectFromFile(FileName,False);
      ExpInfoOle.DoVerb(ovShow);
      ExpInfoOle.SetFocus;
      v:=ExpInfoOle.OleObject;
      v:=v.application.activeworkbook.activesheet;
      v.range['A2']:='AAA';
      

  5.   

    我用ADO连报错,我是按李维在Delphi 5下的方法做的,但在Delphi 6下就不行,我以前问过这个问题,但找不到那个贴子了,请再指教一下。
      

  6.   

    ADO报‘From 子句语法错误’,为什么?