talnewtoperl has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for a command in OLE that will create several excel worksheets, with a number i choose first of all, and not to add one every time. thank you very much
  • Comment on Creating desired number of worksheets in excel

Replies are listed 'Best First'.
Re: Creating desired number of worksheets in excel
by davies (Monsignor) on Sep 11, 2013 at 12:18 UTC

    Beating my own drum, but the technique for creating n sheets in a new file without looping is shown in RFC Tutorial - Deleting Excel Rows, Columns and Sheets. Just don't leave the user with a mess to clear up, but the technique for that is shown too, as is the explanation of what creates a mess.

    Regards,

    John Davies

Re: Creating desired number of worksheets in excel
by Corion (Patriarch) on Sep 11, 2013 at 10:19 UTC
Re: Creating desired number of worksheets in excel
by marto (Cardinal) on Sep 11, 2013 at 10:23 UTC
Re: Creating desired number of worksheets in excel
by poj (Abbot) on Sep 11, 2013 at 10:49 UTC
    Use count in add method.
    my $add = 10; my $workbook = $excel-> Workbooks -> Add(); my $last = $workbook->Sheets->Count; $workbook->Sheets->Add({After=>$workbook->Sheets($last), Count=>$add});
    poj
Re: Creating desired number of worksheets in excel
by ansh batra (Friar) on Sep 11, 2013 at 10:25 UTC
Re: Creating desired number of worksheets in excel
by ansh batra (Friar) on Sep 11, 2013 at 10:31 UTC

    you mean ?

    for(1.2..$count) { $Sheet = $Book->Worksheets($_); $Sheet->Activate(); }

Re: Creating desired number of worksheets in excel
by talnewtoperl (Initiate) on Sep 11, 2013 at 11:00 UTC
    thank you! one more question, is there a command that i can check if "Sheet3" for example is open? by sheet number or name?

      Have you read Using Win32::OLE and Excel - Tips and Tricks? It contains many helpful tips, and also how to find the Excel methods within the Excel documentation.

      If you think you've seen this response before, maybe now is the time to follow its advice.
A reply falls below the community's threshold of quality. You may see it by logging in.