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 !!:(

Recommended Answers

All 9 Replies

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.

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 ;)

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.

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

thank you.very very much!

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

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.

what about intraweb and export to excel?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.