procedure
TForm1
.
Button2Click(Sender: TObject);
Var
i,ind:
Integer
;
ExcelApp,Sheet:Variant;
begin
ExcelApp:=CreateOleObject(
'Excel.Application'
);
ExcelApp
.
WorkBooks
.
Add;
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Name:=
'Отчет'
;
sheet:=ExcelApp
.
WorkBooks[
1
].WorkSheets[
'Отчет'
];
Sheet
.
Cells[
1
,
1
].Columns
.
Font
.
Bold:=
True
;
Sheet
.
Cells[
1
,
1
].Columns
.
Font
.
Size:=
12
;
Sheet
.
Cells[
1
,
1
].Columns
.
Borders
.
LineStyle:=
1
;
Sheet
.
Cells[
1
,
1
]:=
'Дата/Время'
;
Sheet
.
Cells[
1
,
2
].Columns
.
Font
.
Bold:=
True
;
Sheet
.
Cells[
1
,
2
].Columns
.
Font
.
Size:=
12
;
Sheet
.
Cells[
1
,
2
].Columns
.
Borders
.
LineStyle:=
1
;
Sheet
.
Cells[
1
,
2
]:=
'Среднее значение'
;
ind:=
2
;
DBGrid1
.
DataSource
.
DataSet
.
First;
For
i:=
1
to
DBGrid1
.
DataSource
.
DataSet
.
RecordCount
do
Begin
Sheet
.
Cells[ind,
1
].Columns
.
Borders
.
LineStyle:=
1
;
Sheet
.
Cells[ind,
1
]:=DBGrid1
.
Fields[
0
].AsString;
Sheet
.
Cells[ind,
2
].Columns
.
Borders
.
LineStyle:=
1
;
Sheet
.
Cells[ind,
2
]:=DBGrid1
.
Fields[
1
].Value;
inc(ind);
DBGrid1
.
DataSource
.
DataSet
.
Next;
end
;
Sheet
.
Columns
.
NumberFormat:=
'# #0,00'
;
ExcelApp
.
Columns
.
AutoFit;
ExcelApp
.
Visible:=
True
;
end
;