Board index » delphi » Dumping data from Delphi 5 app to Excel

Dumping data from Delphi 5 app to Excel

The method of passing data to Excel from my Delphi 4 app worked fine until i
upgraded to Delphi 5.  The method i had used no longer works and i acan not
make head nor tail of the new Excel Servers.

Has anyone else had the same problem or no how to send data to Excel from D5
apps.

Any help will be much appreciated

The method i used in D4 i have attached below.  It goes through a database
dumping two pieces of info into a row for each record in the database, it
also then sorts the list in Excel.

Var XLApp: Variant;
     Sheet: Variant;
    i:Integer;
begin
  XLApp:= CreateOleObject('Excel.Application');
  XLApp.Workbooks.Add('',xlWBatWorkSheet);
  XLApp.Workbooks[1].WorkSheets[1].Name := 'Security Matrix';

  Sheet := XLApp.Workbooks[1].WorkSheets['Security Matrix'];
  With IPSfWData do begin
    lqsec.gotop;
    i:=2;
    Sheet.Cells[1, 1] := 'Access Description';
    Sheet.Cells[1, 2] := 'Matrix';
    Sheet.Range['A1:B1'].Font.Bold := True;
    Sheet.Columns[1].ColumnWidth := 46;
    Sheet.Columns[2].ColumnWidth := 12;
    while not lqsec.eof do begin
      Sheet.Cells[i, 1] := lqsecname.value;
      Sheet.Cells[i, 2] := lqsecsecvalue.value;
      lqsec.next;
      i:=i+1;
    end;
    Sheet.Range['A2'].Sort(Sheet.Range['A1'],xlAscending);
  end;
  XLApp.Visible := True;

Tony Wood
Turnkey Computer Technology
Glasgow

 

Re:Dumping data from Delphi 5 app to Excel


In particular i need to know how to connect to Excel and create a new
workbook.  Also how to call the sort command to sort a two column table by
the first column only.

Thanks

Tony

Re:Dumping data from Delphi 5 app to Excel


The server classes in D5 are based on Excel97. If you originally wrote it
using a different version of Excel, then that might be your problem. You can
still use your other Excel_TLB file in D5 and that should put you exactly
where you were before.

have fun
--
Binh Ly
Visit my COM Notes at http://www.castle.net/~bly/com

Quote
Tony Wood <tony_w...@tctl.co.uk> wrote in message

news:7t2bcu$9ef11@forums.borland.com...
Quote
> The method of passing data to Excel from my Delphi 4 app worked fine until
i
> upgraded to Delphi 5.  The method i had used no longer works and i acan
not
> make head nor tail of the new Excel Servers.

> Has anyone else had the same problem or no how to send data to Excel from
D5
> apps.

> Any help will be much appreciated

> The method i used in D4 i have attached below.  It goes through a database
> dumping two pieces of info into a row for each record in the database, it
> also then sorts the list in Excel.

> Var XLApp: Variant;
>      Sheet: Variant;
>     i:Integer;
> begin
>   XLApp:= CreateOleObject('Excel.Application');
>   XLApp.Workbooks.Add('',xlWBatWorkSheet);
>   XLApp.Workbooks[1].WorkSheets[1].Name := 'Security Matrix';

>   Sheet := XLApp.Workbooks[1].WorkSheets['Security Matrix'];
>   With IPSfWData do begin
>     lqsec.gotop;
>     i:=2;
>     Sheet.Cells[1, 1] := 'Access Description';
>     Sheet.Cells[1, 2] := 'Matrix';
>     Sheet.Range['A1:B1'].Font.Bold := True;
>     Sheet.Columns[1].ColumnWidth := 46;
>     Sheet.Columns[2].ColumnWidth := 12;
>     while not lqsec.eof do begin
>       Sheet.Cells[i, 1] := lqsecname.value;
>       Sheet.Cells[i, 2] := lqsecsecvalue.value;
>       lqsec.next;
>       i:=i+1;
>     end;
>     Sheet.Range['A2'].Sort(Sheet.Range['A1'],xlAscending);
>   end;
>   XLApp.Visible := True;

> Tony Wood
> Turnkey Computer Technology
> Glasgow

Other Threads