Source Code



SQL data to Excel

  • anonymous
  • Dec 19' 13
  • Delphi
  • 258
  • 113
  • United States

the syntax simple here


 

procedure Trydc.suiButton2Click(Sender: TObject);


var
        i,row,column:integer;
begin
        Try
                ExcelApplication1.Connect;
        Except
                MessageDlg(''Excel may not be installed'',mtError, [mbOk], 0);
                Abort;
        End;
        ExcelApplication1.Visible[0]:=True;
        ExcelApplication1.Caption:=''Excel Application'';
        ExcelApplication1.Workbooks.Add(Null,0);
        ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
        ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
        ADOQuery1.Open;
        row:=1;
        While Not(ADOQuery1.Eof) do
        begin
                column:=1;
                for i:=1 to ADOQuery1.FieldCount do
                begin
                ExcelWorksheet1.Cells.Item[row,column]:=ADOQuery1.fields[i-1].AsString;
                column:=column+1;
                end;
        ADOQuery1.Next;
        row:=row+1;
        end;
end;
  • Tags : delphi, sql, data, excel
comments powered by Disqus

Related Code

Execute a JavaScript Code on a TWebBrowser Document

Save a StringGrid as a CSV file

Empty Recylce Bin

Get MAC Address of Network Card

Kill Active Program

Resizable forms and size grip

Simple Like Function

Suspend the PC

Get current url

Using WinZip as a backup tool



Category

Tag Linked