I did some work with this for a customer several years ago and they are
still using that product. My recollection is of having problems similar to
what you describe. (See below) - note I am using Delphi 3, it didn't come
with TExcelReport

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Michael Switzer
> Sent: Friday, 16 June 2000 16:35
> To: Multiple recipients of list delphi
> Subject: [DUG]: Talking to Excel.
>
>
> Hi all,
>
> I'm trying to get Delphi 4 to create a chart in Excel.  Stop sniggering.
>
> Does anyone know how to get an Excel 'Range' object to work?  The docs say
> it expects an argument of - in VB speak - ("A1:H8")  so that it looks like
> ...Range("A1:H8")...
>
> So far my code does the following:
>
> <snip>
> ER := TExcelReport.Create;  //  ER.OLEExcel is the OLE automation
> object for
> the Excel Application
> <snip>
> ASHT := ER.OLEExcel.ActiveWorkbook.ActiveSheet;
> ASHT.Range('A1');  // error
> <snip>
>
> Variations on this error line (like below) don't work as far as I can see.
> ASHT.Range.Cells(1,1);
> ASHT.Range('"A1'");
> ASHT.Range(ASHT.Range.Cells(1,1), ASHT.Range.Cells(2,2)):
>
> My aim is to get back a range object that I can then use to help create my
> chart.

Not sure what you're trying to do. This is what our code does in order to
fill a range of cells (called in a For loop). At least it does work:

procedure TMainForm.WriteCellString(CRow,CCol:integer;Data:String);
begin
     ExcelApp.Goto('R'+IntToStr(CRow)+'C'+IntToStr(CCol));
     ExcelApp.ActiveCell.Value:=Data;
end;

procedure TMainForm.ReadCellString(CRow,CCol:integer; var Data:string);
//[1.33+]
var D:OleVariant;
begin
     ExcelApp.Goto('R'+IntToStr(CRow)+'C'+IntToStr(CCol));
     D:=ExcelApp.ActiveCell.Value;
     Data:=String(D);
end;

procedure TMainForm.ClearCell(CRow,CCol:integer);
begin
     ExcelApp.Goto('R'+IntToStr(CRow)+'C'+IntToStr(CCol));
     ExcelApp.ActiveCell.ClearContents;
end;

ExcelApp is an object created and assigned as follows (Delphi 3) :

               ExcelApp:=CreateOLEObject('Excel.Application');
***OR***
               ExcelApp:=GetActiveOLEObject('Excel.Application');


               ExcelApp.Workbooks.Open('SomeFileName',0,False);

        ExcelApp.ActiveWorkbook.Worksheets.Item(1).Activate;


after which we are ready to read or write cells using the code above.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to