unit Otchot223;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,UDM, StdCtrls, ExtCtrls, DB, ADODB, Grids, DBGrids,comobj;

type
  TForm23 = class(TForm)
    DataSource1: TDataSource;
    ADOQuery1: TADOQuery;
    Panel1: TPanel;
    Button1: TButton;
    Button3: TButton;
    DBGrid1: TDBGrid;
    procedure FormActivate(Sender: TObject);
    procedure Button3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form23: TForm23;

implementation

uses Menu1;

{$R *.dfm}

procedure TForm23.Button1Click(Sender: TObject);
begin
close();
end;

procedure TForm23.Button3Click(Sender: TObject);

var
excel, list, data,shapka,dp: variant;
i,j,ii,jj:integer;
begin
Otchot223.form23.ADOQuery1.open;
ii:= Otchot223.form23.ADOQuery1.RecordCount;
jj:=Otchot223.form23.ADOQuery1.FieldCount;
excel:=createoleobject('excel.application');
excel.workBooks.add;
Data:=vararraycreate([1,ii,1,jj],varvariant);
Otchot223.form23.ADOQuery1.First;
for i:=1 to ii do
begin
for j:=1 to jj do
begin
data[i,j]:=Otchot223.form23.ADOQuery1.Fields[j-1].AsString;
end;
Otchot223.form23.ADOQuery1.Next;
end;
Shapka:= varArrayCreate([1,jj],varvariant);
for i:=1 to jj do
shapka[i]:= Otchot223.form23.DBGrid1.Columns[i-1].Title.caption;;
list:=excel.worksheets[1];
Dp:=list.range[list.cells[3,2],list.cells[3,jj]];
begin
list.name:='Должники';
list.rows[1].font.size:=14;
list.range['b1'].value:='Список должников';
Dp.value:=shapka;
Dp:=list.range[list.cells[4,2],list.cells[3+ii,jj]];
Dp.value:=Data;
for i:=1 to jj do
if i<>2 then
list.columns.item[i].autofit;
list.columns[2].columnwidth:=16 ;
list.range[list.cells[3,2],list.cells[ii+3,jj]].borders.linestyle:=1;
excel.visible:=true;
end;
end;

procedure TForm23.Button3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Menu1.form1.StatusBar1.Panels[0].Text:='Для перевода информации из таблицы в Excel ' ;
end;

procedure TForm23.FormActivate(Sender: TObject);
begin
ADOQuery1.Open;
end;

end.
