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

        }
    }
}

抛出错误File not found,但路径是正确的。请指教。 添加 -
EDIT
warn -e $FileName ? "File exists":"File does not exist";
ERROR

Unrecognized escape \O passed through at perltest2.cgi line 6.
File does not exist at perltest2.cgi line 10.
File not found.
4

1 回答 1

4
Unrecognized escape \O passed through at perltest2.cgi line 6.

看起来你有:

my $FileName = "C:\excel\Onsite_Report(15).xlsx";

Perl 在这个字符串中看到两个转义序列:\e\O. \e不会导致错误,因为它是有效的转义:

\e 转义字符。

但事实\O并非如此。使用单引号,这样 Perl 就不会插入转义:

my $FileName = 'C:\excel\Onsite_Report(15).xlsx';
于 2013-09-20T09:51:05.763 回答