1

我正在尝试探索 Perl 并做一些示例代码。我尝试使用 Perl 阅读 excel。我下载Spreadsheet-ParseExcel并安装在我的机器上。我尝试了以下代码:

代码

#!"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";

            }
        }
    }

它会抛出这样的错误:

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.

请指教。

4

2 回答 2

3

你有一个不寻常的双引号字符。

my $FileName = “C:/excel/Onsite_Report(15).xlsx";
#              ^------ here
于 2013-09-20T08:35:50.627 回答
1

Spreadsheet::ParseExcel 不解析 xlsx 文件(除非它们只是错误命名的 xls 文件)。为此,您应该使用Spreadsheet::XLSX。您可以尝试使用“ dir /x”显示的短文件名

于 2013-09-20T18:12:17.327 回答