in reply to parsing excel sheet from a perl program
Nonetheless, your script (with its numerous problems intact) reads the spreadsheet au.xls (when that's in same dir with the script and presumably, when au.xls actually exists where you say it does.
au.xls, in same dir with script:and, changing your test in line 12 to if ($row > 0) { (still not the right way to do this, but workable), execution looks like this:captionColA captionColB captionColC http://abc.com 3 abc http://www.xyz.com 4 xyz foo.bar 5 fb
pl_test>perl 827414.pl http://abc.com http://www.xyz.com foo.bar Use of uninitialized value in foreach loop entry at 827414.pl line 12. Use of uninitialized value in foreach loop entry at 827414.pl line 12. Argument "" isn't numeric in numeric gt (>) at 827414.pl line 14. Use of uninitialized value in foreach loop entry at 827414.pl line 12. Use of uninitialized value in foreach loop entry at 827414.pl line 12. Argument "" isn't numeric in numeric gt (>) at 827414.pl line 14. pl_test>
And the minimally-modified (ie, largely uncorrected) script:
#!/usr/bin/perl use strict; use warnings; # id: 827414 use Spreadsheet::ParseExcel; my $excel = Spreadsheet::ParseExcel::Workbook->Parse("au.xls"); my $excel_file_url; #start looping the Excel sheet for my $sheet (@{$excel->{Worksheet}}) { $sheet->{MaxRow} ||= $sheet->{MinRow}; for my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) { #looping for each row if ($row > 0) { #get the file url path from excel sheet at corresponding +row, col 0 my $cell_value=$sheet->{Cells}[$row][0]; $excel_file_url=$cell_value->{Val}; print $excel_file_url . " \n"; } } }
HTH.
|
|---|