Board index » delphi » How can I add new sheet to Excel

How can I add new sheet to Excel

There is default 3 sheet in Excel bu I need to more. How can I add new
sheet?
 

Re:How can I add new sheet to Excel


          ExcelObject.Worksheets.Add(EmptyParam, ExcelObject.ActiveSheet, 1,
xlWorksheet, LCID);
Quote
"Yucel" <ykarapi...@hotmail.com> wrote in message news:3cda70a6_2@dnews...
> There is default 3 sheet in Excel bu I need to more. How can I add new
> sheet?

Re:How can I add new sheet to Excel


It give like some this error:
Raised exception class EOleSysError with message 'Invalid parameter number'

Can you give me working example with parameter detailed?

Re:How can I add new sheet to Excel


Quote
Yucel wrote:
> It give like some this error:
> Raised exception class EOleSysError with message 'Invalid parameter number'

> Can you give me working example with parameter detailed?

var
   Excel: ExcelApplication;
   Hoja: ExcelWorksheet;

begin
   ...
   Hoja :=
Excel.Sheets.Add(EmptyParam,Excel.Sheets[Excel.Sheets.Count],1,EmptyParam,LCID)
as ExcelWorksheet;
end;

This works fine for me

--
JAM - Reljate y disfruta...

Re:How can I add new sheet to Excel


I'm using Delphi 3.
{uses ComObj}

It displaying this errors:

Undefined identifier: 'ExcelApplication'.
Undefined identifier: ExcelWorksheet'.
Undefined identifier: EmptyParam'.
'(' expected but ')' found.
.........

Jess Avils Martnez , <3CDB8566.8090...@PEICHjazzfree.com> iletisine
yazdy...

Quote
>Yucel wrote:

>> It give like some this error:
>> Raised exception class EOleSysError with message 'Invalid parameter
number'

>> Can you give me working example with parameter detailed?

>var
>   Excel: ExcelApplication;
>   Hoja: ExcelWorksheet;

>begin
>   ...
>   Hoja :=
>Excel.Sheets.Add(EmptyParam,Excel.Sheets[Excel.Sheets.Count],1,EmptyParam,L
CID)
>as ExcelWorksheet;
>end;

>This works fine for me

>--
>JAM - Reljate y disfruta...

Re:How can I add new sheet to Excel


Quote
Yucel wrote:
> I'm using Delphi 3.
> {uses ComObj}

> It displaying this errors:

> Undefined identifier: 'ExcelApplication'.
> Undefined identifier: ExcelWorksheet'.
> Undefined identifier: EmptyParam'.
> '(' expected but ')' found.
> .........

> Jess Avils Martnez , <3CDB8566.8090...@PEICHjazzfree.com> iletisine
> yazdy...

>>Yucel wrote:

>>>It give like some this error:
>>>Raised exception class EOleSysError with message 'Invalid parameter

> number'

>>>Can you give me working example with parameter detailed?

>>var
>>  Excel: ExcelApplication;
>>  Hoja: ExcelWorksheet;

>>begin
>>  ...
>>  Hoja :=
>>Excel.Sheets.Add(EmptyParam,Excel.Sheets[Excel.Sheets.Count],1,EmptyParam,L

> CID)

>>as ExcelWorksheet;
>>end;

>>This works fine for me

>>--
>>JAM - Reljate y disfruta...

You can replace ExcelApplication and ExcelWorksheet by Variant or
OleVariant and delete the "as ExcelWorksheet". I think EmptyParam can be
replaced by ''.

--
JAM - Reljate y disfruta...

Re:How can I add new sheet to Excel


var
  Excel, Hoja: OleVariant;
begin
  Excel := CreateOleObject('Excel.Application');
  Excel.Visible := true;
  Excel.Workbooks.Add;
  Hoja:=Excel.Sheets.Add('',Excel.Sheets[Excel.Sheets.Count],1,'',LCID(1));
end;
// it doesn't work with LCID, so I write LCID(1)

In runtime, it giving 'Invalid parameter number' error. What is wrong?

Re:How can I add new sheet to Excel


You can skip any parameters in Add method:
Hoja := Excel.Sheets.Add;

--
With best regards, Mike Shkolnik
E-Mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Yucel <ykarapi...@hotmail.com> D??? ???Y??:3cdbce7a_1@dnews...

Quote
> var
>   Excel, Hoja: OleVariant;
> begin
>   Excel := CreateOleObject('Excel.Application');
>   Excel.Visible := true;
>   Excel.Workbooks.Add;

Hoja:=Excel.Sheets.Add('',Excel.Sheets[Excel.Sheets.Count],1,'',LCID(1));
Quote
> end;
> // it doesn't work with LCID, so I write LCID(1)

> In runtime, it giving 'Invalid parameter number' error. What is wrong?

Re:How can I add new sheet to Excel


It is working, finally. Thank you very much Mike and all...

Mike Shkolnik , <3cdfa4f3_1@dnews> iletisine yazdy...

Quote
>You can skip any parameters in Add method:
>Hoja := Excel.Sheets.Add;

>--
>With best regards, Mike Shkolnik
>E-Mail: mshkol...@scalabium.com
>WEB: http://www.scalabium.com

>Yucel <ykarapi...@hotmail.com> D??? ???Y??:3cdbce7a_1@dnews...
>> var
>>   Excel, Hoja: OleVariant;
>> begin
>>   Excel := CreateOleObject('Excel.Application');
>>   Excel.Visible := true;
>>   Excel.Workbooks.Add;

>Hoja:=Excel.Sheets.Add('',Excel.Sheets[Excel.Sheets.Count],1,'',LCID(1));
>> end;
>> // it doesn't work with LCID, so I write LCID(1)

>> In runtime, it giving 'Invalid parameter number' error. What is wrong?

Re:How can I add new sheet to Excel


Quote
"Yucel" <ykarapi...@hotmail.com> wrote:
>var
>  Excel, Hoja: OleVariant;
>begin
>  Excel := CreateOleObject('Excel.Application');
>  Excel.Visible := true;
>  Excel.Workbooks.Add;
>  Hoja:=Excel.Sheets.Add('',Excel.Sheets[Excel.Sheets.Count],1,'',LCID(1));
>end;
>// it doesn't work with LCID, so I write LCID(1)

>In runtime, it giving 'Invalid parameter number' error. What is wrong?

Try to remove last parameter:

Hoja:=Excel.Sheets.Add('',Excel.Sheets.Excel.Sheets.Count],1,'');

Re:How can I add new sheet to Excel


This time it giving this error :
"Class of Sheets Add method is unsuccessful"

But this working:
Hoja := Excel.Sheets.Add;

Thanks...

Jess Avils Martnez , <3cdfd990$1_1@dnews> iletisine yazdy...

Quote

>"Yucel" <ykarapi...@hotmail.com> wrote:
>>var
>>  Excel, Hoja: OleVariant;
>>begin
>>  Excel := CreateOleObject('Excel.Application');
>>  Excel.Visible := true;
>>  Excel.Workbooks.Add;

Hoja:=Excel.Sheets.Add('',Excel.Sheets[Excel.Sheets.Count],1,'',LCID(1));
Quote
>>end;
>>// it doesn't work with LCID, so I write LCID(1)

>>In runtime, it giving 'Invalid parameter number' error. What is wrong?

>Try to remove last parameter:

>Hoja:=Excel.Sheets.Add('',Excel.Sheets.Excel.Sheets.Count],1,'');

Other Threads