Programming
--
Questions
--
Followers
Top Experts
DELPHI - ADO Dataset to Excel
I want to export the records of a table in MS Access to a excel file or a tab delimited text file in DELPHI. Here i have tried with ADOTable since i have no idea of exporting it with ADODataset. My code is,
procedure TForm1.Button4Click(Sender : TObject);
const
adClipString = 2;
ColumnDelimiter = ';';
RowDelimiter = #13#10;
var
s : String;
fs : TFileStream;
export_filename:string;
ADOTable1:TADOTable;
rs123:TADODataset;
begin
connect;
rs123:=TADOdataset.create( nil);
rs123.Connection :=con;
rs123.CommandText :='select * from b_table1';
rs123.Open;
export_filename:='c:\test. csv';
ADOTable1:=TADOTable.Creat e(nil);
ADOTable1.Connection :=con;
ADOTable1.TableName :='b_table1';
ADOTable1.Open;
s := ADOTable1.Recordset.GetStr ing(adClip String, ADOTable1.Recordset.Record Count, ColumnDelimiter, RowDelimiter, '');
fs := TFileStream.Create(export_ filename, fmCreate);
try
fs.WriteBuffer(s[1], Length(s));
finally
fs.Free;
end;
showmessage('completed');
end;
When i opened the excel file, i found that all the field values are stored in one cell separated by commas. But i want each of the field value in each column.
I want the output file with details in the following format(in the case of text file):
H FirstName LastName Age !!
A Ram Ramu 21 !!
A Sam Samu 19 !!
A Sen Senu 23 !!
In case of Excel, i want each field value in separate columns.
Please help me.
procedure TForm1.Button4Click(Sender
const
adClipString = 2;
ColumnDelimiter = ';';
RowDelimiter = #13#10;
var
s : String;
fs : TFileStream;
export_filename:string;
ADOTable1:TADOTable;
rs123:TADODataset;
begin
connect;
rs123:=TADOdataset.create(
rs123.Connection :=con;
rs123.CommandText :='select * from b_table1';
rs123.Open;
export_filename:='c:\test.
ADOTable1:=TADOTable.Creat
ADOTable1.Connection :=con;
ADOTable1.TableName :='b_table1';
ADOTable1.Open;
s := ADOTable1.Recordset.GetStr
fs := TFileStream.Create(export_
try
fs.WriteBuffer(s[1], Length(s));
finally
fs.Free;
end;
showmessage('completed');
end;
When i opened the excel file, i found that all the field values are stored in one cell separated by commas. But i want each of the field value in each column.
I want the output file with details in the following format(in the case of text file):
H FirstName LastName Age !!
A Ram Ramu 21 !!
A Sam Samu 19 !!
A Sen Senu 23 !!
In case of Excel, i want each field value in separate columns.
Please help me.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Here's how to use ADO to Read/Write to XLS files: http://delphi.about.com/od/database/l/aa090903a.htm
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Programming
--
Questions
--
Followers
Top Experts
Programming includes both the specifics of the language you’re using, like Visual Basic, .NET, Java and others, but also the best practices in user experience and interfaces and the management of projects, version control and development. Other programming topics are related to web and cloud development and system and hardware programming.