procedure
TForm1
.
Button4Click(Sender: TObject);
var
XLApp,Sheet,Colum:Variant;
glavnay, telefon, i :
Integer
;
begin
XLApp:= CreateOleObject(
'Excel.Application'
);
XLApp
.
Visible:=
true
;
XLApp
.
Workbooks
.
Add(-
4167
);
XLApp
.
Workbooks[
1
].WorkSheets[
1
].Name:=
'Отчёт'
;
Colum:=XLApp
.
Workbooks[
1
].WorkSheets[
'Отчёт'
].Columns;
Colum
.
Columns[
1
].ColumnWidth:=
20
;
Colum
.
Columns[
2
].ColumnWidth:=
20
;
Colum
.
Columns[
3
].ColumnWidth:=
20
;
Colum
.
Columns[
4
].ColumnWidth:=
20
;
Colum:=XLApp
.
Workbooks[
1
].WorkSheets[
'Отчёт'
].Rows;
Colum
.
Rows[
2
].Font
.
Bold:=
true
;
Colum
.
Rows[
1
].Font
.
Bold:=
true
;
Colum
.
Rows[
1
].Font
.
Color:=clBlue;
Colum
.
Rows[
1
].Font
.
Size:=
14
;
Sheet:=XLApp
.
Workbooks[
1
].WorkSheets[
'Отчёт'
];
Sheet
.
Cells[
1
,
2
]:=
'Телефонный справочник'
;
Sheet
.
Cells[
2
,
1
]:=
'Фамилия'
;
Sheet
.
Cells[
2
,
2
]:=
'Имя'
;
Sheet
.
Cells[
2
,
3
]:=
'Стационарный'
;
Sheet
.
Cells[
2
,
4
]:=
'Мобильный'
;
glavnay:=
3
;
telefon:=
3
;
for
i:=
0
to
form1
.
ADOTable2
.
RecordCount-
1
do
begin
Sheet
.
Cells[telefon,
3
]:=form1
.
ADOTable2
.
Fields
.
Fields[
2
].AsString;
Sheet
.
Cells[telefon,
4
]:=form1
.
ADOTable2
.
Fields
.
Fields[
3
].AsString;
inc(telefon);
form1
.
ADOTable2
.
Next;
end
;
Sheet
.
Cells[glavnay,
1
]:=form1
.
ADOTable1
.
Fields
.
Fields[
1
].AsString;
Sheet
.
Cells[glavnay,
2
]:=form1
.
ADOTable1
.
Fields
.
Fields[
2
].AsString;
end
;