Board index » delphi » Multiple sheets in Excel

Multiple sheets in Excel


2005-09-07 08:26:04 PM
delphi92
At the moment I have:
var
XLApp, Sheet, Data: OLEVariant;
begin
try
XLApp := CreateOleObject('Excel.Application');
XLApp.Visible := False;
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp.Workbooks[1].WorkSheets[1];
....code to import data
... etc
This creates a workbook with one sheet, but how do I create a second sheet
and get access to it?
 
 

Re:Multiple sheets in Excel

Quote
var
XLApp, Sheet, Data: OLEVariant;
begin
try
XLApp := CreateOleObject('Excel.Application');
XLApp.Visible := False;
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp.Workbooks[1].WorkSheets[1];
XLApp.Workbooks[1].Worksheets.Add;
Oliver Townshend
 

Re:Multiple sheets in Excel

"Oliver Townshend" <oliveratzipdotcomdotau>writes
Quote
>var
>XLApp, Sheet, Data: OLEVariant;
>begin
>try
>XLApp := CreateOleObject('Excel.Application');
>XLApp.Visible := False;
>XLApp.Workbooks.Add(xlWBatWorkSheet);
>Sheet := XLApp.Workbooks[1].WorkSheets[1];

XLApp.Workbooks[1].Worksheets.Add;

Thanks for replying to such a basic question - that what I tried first but I
got an "illegal OLE error" message.
I have now found the error came from a stupid typo 2 lines later that meant
my code worked only for 1 sheet - and since it did work before I added the
line for another sheet I assumed that was the problem and never noticed the
de{*word*81} cursor was 2 lines away :(
 

Re:Multiple sheets in Excel

XLApp := CreateOleObject('Excel.Application');
XLBook := XLApp.Workbooks.Add;
Sheet := XLBook.Sheets.Add;
"Lorne" <XXXX@XXXXX.COM>writes
Quote
At the moment I have:

var
XLApp, Sheet, Data: OLEVariant;
begin
try
XLApp := CreateOleObject('Excel.Application');
XLApp.Visible := False;
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet := XLApp.Workbooks[1].WorkSheets[1];
....code to import data
... etc

This creates a workbook with one sheet, but how do I create a second sheet
and get access to it?