Reputation: 6403
I'm trying to explore Perl and do some sample code. I tried to read excel use Perl. I downloaded Spreadsheet-ParseExcel
and installed in my machine. I tried below code:
Code
#!"C:\Perl64\bin\perl.exe"
use CGI;
use strict;
use Spreadsheet::ParseExcel;
my $FileName = “C:/excel/Onsite_Report(15).xlsx";
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse($FileName);
die $parser->error(), ".\n" if ( !defined $workbook );
# Following block is used to Iterate through all worksheets
# in the workbook and print the worksheet content
for my $worksheet ( $workbook->worksheets() ) {
# Find out the worksheet ranges
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
# Return the cell object at $row and $col
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
print "Row, Col = ($row, $col)\n";
print "Value = ", $cell->value(), "\n";
}
}
}
and it throws error like this:
C:\xampp\cgi-bin>perl perltest3.cgi
Unrecognized character \xE2; marked by <-- HERE after ileName = <-- HERE near co
lumn 20 at perltest3.cgi line 6.
Please advice.
Upvotes: 1
Views: 957
Reputation: 6524
Spreadsheet::ParseExcel does not parse xlsx files (unless they are just mis-named xls files). For that, you should use Spreadsheet::XLSX. And you might try using the short filename as displayed by "dir /x
"
Upvotes: 1
Reputation: 67900
You have an unusual double quote character there.
my $FileName = “C:/excel/Onsite_Report(15).xlsx";
# ^------ here
Upvotes: 3