Code:
procedure TfrmTest.exportToExcel();
var
row:integer;
begin
row:=1;
//membuat+mengkoneksikan dokumen,workbook,worksheet
ExcelApp.Connect;
ExcelApp.Visible[0]:=False;
ExcelApp.Workbooks.Add(1,0);
ExcelWB.ConnectTo(ExcelApp.ActiveWorkbook);
ExcelWS.ConnectTo(ExcelWb.ActiveSheet as _Worksheet);
//tampilkan ke excel
sqlData.first;
while not(sqlData.Eof) do
begin
with ExcelWS,sqlData do
begin
Range['A'+inttostr(row),'A'+inttostr(row)].Value:=fields[0].asstring; //field pertama di kolom A
Range['B'+inttostr(row),'B'+inttostr(row)].Value:=fields[1].asstring; //field kedua di kolom B, dst
//dst..
inc(row);
next;
end;
end;
ExcelApp.Visible[0]:=True;
end;