Main Logo
Articles   Members Online:
-Article/Tip Search
-News Group Search over 800,000 Borland news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Delphi: How to transfer data from any database to excel using Variant
Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to transfer data from any database to excel using Variant Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Data Transfer to Excel 05-Oct-04
Category
ActiveX
Language
Delphi All Versions
Views
678
User Rating
8.5
# Votes
4
Replies
0
Publisher:
Gara, Mekan
Reference URL:
			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   begin 
10  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 do 
16     begin 
17      q:=filName+1; 
18      sheet.Cells[1,q]:=DMod.OgrSiralaQuery.Fields[filName].FieldName; 
19     end; 
20  for r:=0 to DMod.OgrSiralaQuery.RecordCount-1 do 
21  begin 
22    for c:=0 to DMod.OgrSiralaQuery.FieldCount-1 do 
23    begin 
24     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!

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC
Advertisement


Share this page
Advertisement
Copyright © 2024 by No Limit Solutions LLC