문제

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

        }
    }
}

Throws the error File not found, but the path is correct. Please advice.
EDIT
added - 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.
도움이 되었습니까?

해결책

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

Looks like you have:

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

Perl sees two escape sequences in this string: \e and \O. The \e doesn't cause an error as it is a valid escape:

\e Escape character.

But the \O isn't. Use single quotes so Perl doesn't interpolate the escapes:

my $FileName = 'C:\excel\Onsite_Report(15).xlsx';
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top