有谁能给我一段例子!
关于在delphi中调用excel的.
并把数据库要显示的值在excel中显示出来.也就是输出报表用excel来输出.

解决方案 »

  1.   

    procedure TSearchanger_Form.BitBtn2Click(Sender: TObject);
    var
       ExcelID: Variant;   
       Rcol: integer;
    begin
         ExcelID := CreateOleObject('Excel.Application');
         ExcelID.Visible := True;
         ExcelID.Caption := '应用程序调用 Microsoft Excel';
         ExcelID.WorkBooks.Add;
         ExcelID.Cells[1, 1].Value := '摊位号';
         ExcelID.Cells[1, 2].Value := '单位名称';
         ExcelID.Cells[1, 3].Value := '单位代码';
         ExcelID.Cells[1, 4].Value := '单位体制';
         ExcelID.Cells[1, 5].Value := '法人';  
      
         query_new.close;
         query_new.sql.clear;
         query_new.sql.add ('Select * From khu');
         query_new.Prepare;
         query_new.Open;     Rcol := 2 ;
         query_new.First;
         While not query_new.Eof Do
         begin
              ExcelID.Cells[Rcol, 1].Value := query_new.FieldByName('摊位号').asstring;
              ExcelID.Cells[Rcol, 2].Value := query_new.FieldByName('单位名称').asstring;
              ExcelID.Cells[Rcol, 3].Value := query_new.FieldByName('单位代码').asstring;
              ExcelID.Cells[Rcol, 4].Value := query_new.FieldByName('单位体制').asstring;
              ExcelID.Cells[Rcol, 5].Value := query_new.FieldByName('法人').asstring;
              inc(Rcol);          query_new.Next; 
         end;