Board index » delphi » Excel 97 OLE ...

Excel 97 OLE ...

I'm trying to get something to work in Excel 97 using CreateOLEObject (or
GetActiveOleObject),
and I'm constantly running into problems.

How do I load an existing excel (.xls) workbook file from disk, and modify
the contents of 1 cell, and then save it back to disk?

I can pretty successfully create a new worksheet in excel, fill data, and
then
save as, but I can't seem to get the initial loading to work properly.

 

Re:Excel 97 OLE ...


Quote
>How do I load an existing excel (.xls) workbook file from disk, and modify
>the contents of 1 cell, and then save it back to disk?

uses OleAuto;
procedure TForm1.Button1Click(Sender: TObject);
var e:Variant;
begin
 try
  e:=GetActiveOleObject('Excel.Application');
 except
  e:=CreateOleObject('Excel.Application');
 end;
 e.visible := true;
 e.Workbooks.add('c:\Dokumenty\tester.xls');
 e.Cells(1,1) := 'XXX';
 e.ActiveWorkbook.save;
 e.quit;
end;

Other Threads