Link to home
Start Free TrialLog in
Avatar of alanjbrown
alanjbrown

asked on

Example code needed to link OleContainer to ExcelApplication

I am trying to connect an ExcelApplication server component to connect to an OleContainer.

something like

excelApplication1.ConnectTo(oleContainer1.Object);

However I can't get the syntax correct. Can someone please provide some sample code for this.

thanks
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

try this:
procedure TForm1.Button1Click(Sender: TObject);
var xls: OleVariant;
    itf: IDispatch;
    xitf: _Workbook;
begin
  OleContainer1.CreateObjectFromFile('C:\Documents and Settings\Lukasz\Pulpit\test.xls', False);
  OleContainer1.DoVerb(0);
  xls := OleContainer1.OleObject;
  if OleContainer1.OleObjectInterface.QueryInterface(IID__Workbook, itf) = S_OK then begin
    xitf := itf as _Workbook;
    ExcelApplication1.ConnectTo(xitf.Application);
    ExcelApplication1.Range['A1', 'B2'].Font.Bold := True;
  end;
end;

ziolko.
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

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
Avatar of alanjbrown
alanjbrown

ASKER

Thanks very much. That was very helpful.