unit Unit11;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, sButton, ExtCtrls, sPanel, RpConBDE, RpRave, RpDefine,
  RpCon, RpConDS, DB, ADODB, Grids, ComObj, DBGrids;

type
  TForm11 = class(TForm)
    DBGrid1: TDBGrid;
    ADOConnection1: TADOConnection;
    ADOTable3: TADOTable;
    ADOTable3FIO: TWideStringField;
    ADOTable3Spec: TWideStringField;
    ADOTable3Kurs: TSmallintField;
    ADOTable3Prav: TSmallintField;
    ADOTable3NePrav: TSmallintField;
    ADOTable3Ocenka: TSmallintField;
    ADOTable3Data: TDateTimeField;
    DataSource2: TDataSource;
    RvDataSetConnection1: TRvDataSetConnection;
    RvProject1: TRvProject;
    RvQueryConnection1: TRvQueryConnection;
    sPanel1: TsPanel;
    sButton1: TsButton;
    procedure FormActivate(Sender: TObject);
    procedure sButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form11: TForm11;

implementation

{$R *.dfm}

procedure TForm11.FormActivate(Sender: TObject);
begin
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+GetCurrentDir+'\Data\Base.mdb;Persist Security Info=False';
ADOConnection1.Connected:=True;
ADOTable3.Active:=True;
end;

procedure TForm11.sButton1Click(Sender: TObject);
var
 XL, XArr: Variant;
 i: Integer;
 j: Integer;
begin
 {не забудьте включить ComObj в список используемых модулей}
 // Создаем массив элементов, полученных в результате запроса
 XArr:=VarArrayCreate([1,ADOTable3.FieldCount],varVariant);
 XL:=CreateOLEObject('Excel.Application');     // Создание OLE объекта
 XL.WorkBooks.add;
 XL.visible:=true;

 j := 1;
 adoTable3.First;
 while not ADOTable3.Eof do
  begin
   i:=1;
   while i<=ADOTable3.FieldCount do
    begin
     XArr[i] := ADOTable3.Fields[i-1].Value;
     i := i+1;
    end;
   XL.Range['A'+IntToStr(j),
   CHR(64+ADOTable3.FieldCount)+IntToStr(j)].Value := XArr;
   ADOTable3.Next;
   j:=j+1;
  end;
 XL.Range['A2',CHR(64+ADOTable3.FieldCount)+IntToStr(j)].select;
 // XL.cells.select;                     // Выбираем все
 XL.Selection.Font.Name:='Arial cur';
 XL.Selection.Font.Size:=10;
 XL.selection.Columns.AutoFit;
 XL.Range['A2','A2'].select;
end;

end.
