Excel maintains all these arrays for you. You don't have to do the work yourself, whether in Perl or anywhere else.

use strict; use warnings; use Win32::OLE; my $excel = Win32::OLE -> new("Excel.Application"); $excel->{Visible} = 1; $excel->{DisplayAlerts}=0; my $oldsheets = $excel->{SheetsInNewWorkbook}; $excel->{SheetsInNewWorkbook} = 5; my $wb = $excel->Workbooks->Add; $excel->{SheetsInNewWorkbook} = $oldsheets; for my $i (1..$wb->Sheets->{Count}) { $wb->Sheets($i)->Cells(1, 1)->{Value} = "Sheet $i"; }

I think the last 3 lines are the equivalent of your matlab code.

Note, however, the work I have done on sheet numbers. I prefer not to use SheetsInNewWorkbook as it gets saved whenever Excel closes normally. You might have some users who have bothered to set up Excel sensibly. They won't take kindly to you changing their default number of sheets. And if your Perl crashes with an Excel instance open, closing that instance will save the current setting, which is why I prefer not to risk it. But that's just my personal paranoia. The saving & restoring I do in my code should be fine.

Regards,

John Davies


In reply to Re: How to operate on multiple Excel worksheets with variable array by davies
in thread How to operate on multiple Excel worksheets with variable array by bill5262

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.