Perl - 找不到文件

标签 perl excel cgi file-not-found

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

最佳答案

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

看起来你有:
my $FileName = "C:\excel\Onsite_Report(15).xlsx";

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

\e Escape character.



但是 \O不是。使用单引号,这样 Perl 就不会插入转义:
my $FileName = 'C:\excel\Onsite_Report(15).xlsx';

关于Perl - 找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18912868/

相关文章:

Perl:将哈希作为子哈希添加到简单哈希

excel - VBAProject 关键字是什么?

c# - 使用 EPPlus 创建的 Excel 图表中的图例颜色不正确

perl - 使用 FCGI 接受 POST 参数

python - cgi.FieldStorage 始终为空 - 从不返回 POSTed 表单数据

python - 如何创建 Perl 代码的 Python 包装器?

perl - 在 Perl 中美化/美化 HTML

c - 在更快的算法和代码检查方面需要帮助 - 将值与数据库数据进行比较

perl - Crypt-SSLeay 无法验证主机名

javascript - 实时时间表编辑和保存