Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Question about ExcelApplication 1

Status
Not open for further replies.

Gigatech

Programmer
Jul 12, 2000
80
CR
Hi, I'm using D7. I have an ExcelApplication, ExcelWorkBook and ExcelWorkSheet on my Form.

I'm using this code to Lauch Excel:

var
NewTemplate,ItemIndex: OleVariant;
begin
ExcelApplication1.Connect;
NewTemplate:=true;
ItemIndex:=1;
ExcelApplication1.Visible[ItemIndex]:=true;
ExcelApplication1.Workbooks.Add(NewTemplate,ItemIndex);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[ItemIndex]);
ExcelWorkSheet1.ConnecTo(ExcelWorkbook1?);
ExcelWorkSheet1.[1,1]:='Hello' ???


How can I connect ExcelWorkSheet1 to ExcelWorkBook1 ?

After that, how do I refer to a specific Cell of ExcelWorkSheet1?

Thanks


 

Here is a "bare bones" routine to put "Hello" into cell A1 of a new worksheet.

Code:
:
:
  private
    { Private declarations }
    LCID: Integer;
:
:
procedure TfrmMain.Button1Click(Sender: TObject);
begin
  LCID := GetUserDefaultLCID;
  ExcelApp.Connect;
  ExcelApp.visible[LCID] := True;
  ExcelApp.Workbooks.Add(EmptyParam,LCID);
  ExcelWorksheet1.ConnectTo(ExcelApp.ActiveSheet as _Worksheet);
  ExcelWorksheet1.Range['A1','A1'].Value := 'Hello';
  ExcelWorksheet1.Disconnect;
  ExcelApp.Disconnect;
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top