Link to home
Start Free TrialLog in
Avatar of kherbst
kherbst

asked on

Excel Ole Automation - early binding

I am currently using late binding to automate Excel from Delphi 3. This is understandbly slow. Could anyone explain to me how to use the early binding approach and the importing of typelibs in this process?
Avatar of ZifNab
ZifNab

Have you already looked at the TExcel component for your purposes?
Avatar of kherbst

ASKER

Yes, but it uses DDE and I don't want that.
Hi

The following example has an OLE Container on a form (oleExcel) and I use that to get the IWorkSheet interface (which is declared in the Excel type library).

procedure TForm1.Button1Click(Sender: TObject);
var
    WS: IWorkSheets;
begin
    oleExcel.AutoActivate := aaManual;
    oleExcel.CreateObject('Excel.Sheet', False);
    oleExcel.DoVerb(ovShow);
    WS := IWorkSheets(oleExcel.OleObjectInterface);
    WS.PrintPreview(False, 0);
end;

To import the type library, choose "Import Type Library" from the Project menu and find the file called "Excel8.olb" in your MSOffice\Office path.  (I am using Delphi 3 with Office 97.)

Regards,
JB
Avatar of kherbst

ASKER

Do I have to use a Ole container in the process or can I use CreateOleObject?
You can use create ole object or CoCreateInstance, whichever suits your purpose.
Avatar of kherbst

ASKER

Thank you, I accept your answer.
ASKER CERTIFIED SOLUTION
Avatar of JimBob091197
JimBob091197

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial