It is very easy to Automate Excell:
Like this using Variants . It is also possible using Interfaces. Transfering data
to excel using same simple loops. See bellow
1 2 procedure TTumOgr.SpeedButton1Click(Sender: TObject);
3 var XApp:Variant;
4 sheet:Variant;
5 r,c:Integer;
6 row,col:Integer;
7 filName:Integer;
8 q:Integer;
9 begin10 XApp:=CreateOleObject('Excel.Application');
11 XApp.Visible:=true;
12 XApp.WorkBooks.Add(-4167);
13 XApp.WorkBooks[1].WorkSheets[1].Name:='Sheet1';
14 sheet:=XApp.WorkBooks[1].WorkSheets['Sheet1'];
15 for filName:=0 to DMod.OgrSiralaQuery.FieldCount-1 do16 begin17 q:=filName+1;
18 sheet.Cells[1,q]:=DMod.OgrSiralaQuery.Fields[filName].FieldName;
19 end;
20 for r:=0 to DMod.OgrSiralaQuery.RecordCount-1 do21 begin22 for c:=0 to DMod.OgrSiralaQuery.FieldCount-1 do23 begin24 row:=r+2;
25 col:=c+1;
26 sheet.Cells[row,col]:=DMod.OgrSiralaQuery.Fields[c].AsString;
27 end;
28 DMod.OgrSiralaQuery.Next;
29 end;
30 XApp.WorkSheets['Sheet1'].Range['A1:AA1'].Font.Bold:=True;
31 XApp.WorkSheets['Sheet1'].Range['A1:K1'].Borders.LineStyle :=13;
32 XApp.WorkSheets['Sheet1'].Range['A2:K'+inttostr(DMod.OgrSiralaQuery.RecordCount-1)].
33 Borders.LineStyle :=1;
34 XApp.WorkSheets['Sheet1'].Columns[1].ColumnWidth:=16;
35 XApp.WorkSheets['Sheet1'].Columns[2].ColumnWidth:=7;
36 XApp.WorkSheets['Sheet1'].Columns[3].ColumnWidth:=19;
37 XApp.WorkSheets['Sheet1'].Columns[4].ColumnWidth:=9;
38 XApp.WorkSheets['Sheet1'].Columns[5].ColumnWidth:=9;
39 XApp.WorkSheets['Sheet1'].Columns[6].ColumnWidth:=9;
40 XApp.WorkSheets['Sheet1'].Columns[7].ColumnWidth:=46;
41 XApp.WorkSheets['Sheet1'].Columns[8].ColumnWidth:=9;
42 XApp.WorkSheets['Sheet1'].Columns[9].ColumnWidth:=7;
43 XApp.WorkSheets['Sheet1'].Columns[10].ColumnWidth:=6;
44 XApp.WorkSheets['Sheet1'].Columns[11].ColumnWidth:=13;
45 46 end;
I hope it will help you, Do not forget to realise XApp which allocated!