We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,708 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

delphi export excel!

hi I want my delphi DB that I made to export to excel file how it is possible?and the most important thing is delphi reports that I made I want them to export as excel files ,plz help me !!:(

7
Contributors
9
Replies
1 Year
Discussion Span
1 Year Ago
Last Updated
11
Views
seto.girl
Newbie Poster
5 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi
I Send you an example that will be useful for you.
note that I use access database. you can use any kind of database instead.

Attachments ExportToExcerl.zip (310.96KB)
fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
Skill Endorsements: 0

Hi i could not log in with my pre user ,,,thx for the example programm plz can you explain more how did you export access db to excel with delphi programm? and the sec question is if I wanted to export my report in delphi that I wrote with sql builder to excel what should I do? the third question is how did u convert ur delphi programm to an exe file? thx for the quick reply ;)

setogirl
Newbie Poster
2 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Dear setogirl
I'm Sorry I don't know what is your mine about

i could not log in with my pre user

But about your Questions :
1- you can Export any kind of Data Base Table to Excel Sheet (not only Access Tables) by Flowing Code

procedure TForm1.Button1Click(Sender: TObject);
var
    XApp:Variant;
    sheet:Variant;
    r,c:Integer;
    row,col:Integer;
    filName:Integer;
    q:Integer;
begin
    XApp:=CreateOleObject('Excel.Application');
    XApp.Visible:=true;
    XApp.WorkBooks.Add(-4167);
    XApp.WorkBooks[1].WorkSheets[1].Name:='Sheet1';
    sheet:=XApp.WorkBooks[1].WorkSheets['Sheet1'];
    for filName:=0 to[U] AdoQuery1[/U].FieldCount-1 do
    begin
        q:=filName+1;
        sheet.Cells[1,q]:=[U]AdoQuery1[/U].Fields[filName].FieldName;
    end;
    for r:=0 to[U] AdoQuery1[/U].RecordCount-1 do
    begin
        for c:=0 to [U]AdoQuery1[/U].FieldCount-1 do
        begin
            row:=r+2;
            col:=c+1;
            sheet.Cells[row,col]:=[U]AdoQuery1[/U].Fields[c].AsString;
        end;
        AdoQuery1.Next;
    end;
    XApp.WorkSheets['Sheet1'].Range['A1:AA1'].Font.Bold:=True;
    XApp.WorkSheets['Sheet1'].Range['A1:K1'].Borders.LineStyle :=13;
    XApp.WorkSheets['Sheet1'].Range['A2:K'+inttostr(AdoQuery1.RecordCount-1)].Borders.LineStyle :=1;
    XApp.WorkSheets['Sheet1'].Columns[1].ColumnWidth:=16;
    XApp.WorkSheets['Sheet1'].Columns[2].ColumnWidth:=7;
    XApp.WorkSheets['Sheet1'].Columns[3].ColumnWidth:=19;
    XApp.WorkSheets['Sheet1'].Columns[4].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[5].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[6].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[7].ColumnWidth:=46;
    XApp.WorkSheets['Sheet1'].Columns[8].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[9].ColumnWidth:=7;
    XApp.WorkSheets['Sheet1'].Columns[10].ColumnWidth:=6;
    XApp.WorkSheets['Sheet1'].Columns[11].ColumnWidth:=13;
end;

ADOQuery1 Is a SQL Query that can connect to many kind of Data Base such as SQLServer,Oracle,Access,etc
2- as I explained you can export any Query Result to Excel sheet .
consider that your report is the result of a SQL Statement that wrote in a Query Object. and by above Code you can export it to Excel Sheet.
3-If you compile your code , delphi compiler make an exe file for your Project automaticly
I hope that my explanation be useful for you.

fayyaz
Junior Poster in Training
66 posts since Jun 2007
Reputation Points: 12
Solved Threads: 10
Skill Endorsements: 0

hi I want my delphi DB that I made to export to excel file how it is possible?and the most important thing is delphi reports that I made I want them to export as excel files ,plz help me !!:(

This is very simple actually ...I have also written some software that you can export your data to several formats..
for example
Aceess DB,
Excel
PDF
XML
MS Word Doc.
I have some of my software for sale for as little as $29.95 checkout my web site as well to see just a list of what we do. http://presoftsol.com

wylddev
Newbie Poster
9 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

thank you.very very much!

traixubac
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

thank you.very very much!

Did my code help out...?
I hope it did..
you're welcome.
I would appreciate some comments on my code in positive fashion :)
thanks

wylddev
Newbie Poster
9 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I really need to know what it is exactly you are trying to do..
if you could write or send me a spec of what it is exactly you are trying to do I could help you code this with no problem.
in order to get my code to work you need to drop a TButton on to a TForm.
replace my procedure call name with what ever name you named your button..
I am giving you the simplest example believe it or not..
let me know what it is you want to do..

Thanks:)

Dear setogirl
I'm Sorry I don't know what is your mine about

But about your Questions :
1- you can Export any kind of Data Base Table to Excel Sheet (not only Access Tables) by Flowing Code

procedure TForm1.Button1Click(Sender: TObject);
var
    XApp:Variant;
    sheet:Variant;
    r,c:Integer;
    row,col:Integer;
    filName:Integer;
    q:Integer;
begin
    XApp:=CreateOleObject('Excel.Application');
    XApp.Visible:=true;
    XApp.WorkBooks.Add(-4167);
    XApp.WorkBooks[1].WorkSheets[1].Name:='Sheet1';
    sheet:=XApp.WorkBooks[1].WorkSheets['Sheet1'];
    for filName:=0 to[U] AdoQuery1[/U].FieldCount-1 do
    begin
        q:=filName+1;
        sheet.Cells[1,q]:=[U]AdoQuery1[/U].Fields[filName].FieldName;
    end;
    for r:=0 to[U] AdoQuery1[/U].RecordCount-1 do
    begin
        for c:=0 to [U]AdoQuery1[/U].FieldCount-1 do
        begin
            row:=r+2;
            col:=c+1;
            sheet.Cells[row,col]:=[U]AdoQuery1[/U].Fields[c].AsString;
        end;
        AdoQuery1.Next;
    end;
    XApp.WorkSheets['Sheet1'].Range['A1:AA1'].Font.Bold:=True;
    XApp.WorkSheets['Sheet1'].Range['A1:K1'].Borders.LineStyle :=13;
    XApp.WorkSheets['Sheet1'].Range['A2:K'+inttostr(AdoQuery1.RecordCount-1)].Borders.LineStyle :=1;
    XApp.WorkSheets['Sheet1'].Columns[1].ColumnWidth:=16;
    XApp.WorkSheets['Sheet1'].Columns[2].ColumnWidth:=7;
    XApp.WorkSheets['Sheet1'].Columns[3].ColumnWidth:=19;
    XApp.WorkSheets['Sheet1'].Columns[4].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[5].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[6].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[7].ColumnWidth:=46;
    XApp.WorkSheets['Sheet1'].Columns[8].ColumnWidth:=9;
    XApp.WorkSheets['Sheet1'].Columns[9].ColumnWidth:=7;
    XApp.WorkSheets['Sheet1'].Columns[10].ColumnWidth:=6;
    XApp.WorkSheets['Sheet1'].Columns[11].ColumnWidth:=13;
end;

ADOQuery1 Is a SQL Query that can connect to many kind of Data Base such as SQLServer,Oracle,Access,etc
2- as I explained you can export any Query Result to Excel sheet .
consider that your report is the result of a SQL Statement that wrote in a Query Object. and by above Code you can export it to Excel Sheet.
3-If you compile your code , delphi compiler make an exe file for your Project automaticly
I hope that my explanation be useful for you.

wylddev
Newbie Poster
9 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

what about intraweb and export to excel?

tco9998
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Maybe I am missing something, but it is easy enough to have Delphi to write to a text file.
Put a comma or semicolon between all columns on each row.
Add a #13 (Carrier return) at end of row.
Then start next row.

Excel can easily import a comma or semicolon delimited textfile, and everything is ok.

It does not actually make an Excel file, but it is readable and importable by Excel.
Best regards.

Morten Brendefu
Light Poster
44 posts since Mar 2011
Reputation Points: 38
Solved Threads: 2
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.5399 seconds using 2.68MB