Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to operate on multiple Excel worksheets with variable array

by davies (Parson)
on Aug 08, 2016 at 11:39 UTC ( #1169350=note: print w/replies, xml ) Need Help??


in reply to How to operate on multiple Excel worksheets with variable array

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

  • Comment on Re: How to operate on multiple Excel worksheets with variable array
  • Download Code

Replies are listed 'Best First'.
Re^2: How to operate on multiple Excel worksheets with variable array
by bill5262 (Acolyte) on Aug 09, 2016 at 07:36 UTC

    Thank you so much.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1169350]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2018-10-17 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (97 votes). Check out past polls.

    Notices?