Hello.
I'm still learing Perl, and am trying to perform the following task -- and am miserably stuck.
Currently I have the following.
1. Open the necessary Excel file
2. Store Workbooks info under var $workbook1
3. Store Wortsheets info under var $worksheets1
my $excel = Win32::OLE -> new("Excel.Application");
$excel->{Visible} = 0;
$excel->{DisplayAlerts}=0;
$excel->{SheetsInNewWorkbook} = 1;
my $workbook1 = $excel->Workbooks->Open($OutFileName);
my $worksheet1 = $workbook1->Worksheets(1);
I later take this info and have Perl to write in the cells of the Excel file (the necessary $Row and $Col are initialized accordingly).
$worksheet1->Cells($Row, $Col)->{'Value'} = $var1;
$worksheet1->Cells($Row, $Col+1)->{'Value'} = $var2;
$worksheet1->Cells($Row, $Col+2)->{'Value'} = $var3;
$worksheet1->Cells($Row, $Col+3)->{'Value'} = $var4;
So far this works fine.
What I intend to do is operate on multiple worksheets instead of just one.
1. Open the necessary Excel file
2. Store Workbooks info under var $workbook1
3. Store Wortsheets info under var(s) $worksheets1, $worksheets2, $worksheets3, $worksheets4, $worksheets5 (or store it into an array if it's possible?
I have a total of 5 worksheets I need to operate on in the Excel file.
I'm trying to for loop the latter process (where I write in the cells) for each worksheet, but I'm trying to find an easier way to recall the $worksheet1, $worksheet2, ..., $worksheet5 variables. Cuz, for now without the proper array variable -- which I yet learned how to in Perl -- I need to do an if statement for each every for loop and write the according code, which is very ineffective.. Is there a way to perform this with an array or something else for the worksheet variable?
I'm more familiar with how Matlab works.. and here's what I would like Perl to do if it were a Matlab script with arrays.
for i = 1:num_worksheets
# write in worksheet[i] cell (j,k) with variable var1
end
Any help is appreciated!