Minggu, 11 April 2010

Delphi: Export Data To Excel

Export Data to Excel on Delphi? it's so easy with TscExcelExport component.
Steps :
1. make some query on a dataset or query component
2. setting TscExcelExport to dataset
3. taraaa…. an excel file will be created, completed with field name from query

hmm… still confused? this is the source code.
Just add button, ADOquery, dan TscExcelExport of course.

try
ADOQuery.Active:=false;
ADOQuery.SQL.Text:=’SELECT id,nama FROM barang’;
ADOQuery.Active:=true;

scExcelExport1.ExcelVisible:=True;
scExcelExport1.LoadDefaultProperties;
scExcelExport1.Dataset:=ADOQuery; //query name
scExcelExport1.WorksheetName:=’Export Data Barang’; //sheet title
scExcelExport1.ConnectTo := ctNewExcel;

scExcelExport1.HeaderText.Text:= ‘DATA BARANG ‘+#13+
‘Diexport Tgl. ‘+FormatDateTime(‘dd MMMM yyyy’,Now);
scExcelExport1.BeginRowTitles:=4; //started row
scExcelExport1.ExportDataset;
finally
scExcelExport1.Disconnect;
end;
to get TscExcelExport component, just click here, also the tutorial.
Have a nice try…!!!
Thanks to Stefan Cruysberghs, this component is very helpfull… ;)

0 comments: