Perl SpreadSheet::XLSX Error: "Cannot open as Zip Archive"
Perl SpreadSheet::XLSX Error: "Cannot open as Zip Archive"
我正在尝试使用 Spreadsheet:XLSX
to read Excel files, but I get this error message with CSV, XLS, and XLSX file uploads. I had it working previously with Spreadsheet::Read
和 CSV 文件。
代码太简单了,我就是不知道要解决什么问题。
文件上传正确,我有正确的路径和文件名。
错误信息:
Cannot open c:\Website\cgi-bin\bidprocess\files\SEIPA-request-0307123509.xlsx as Zip archive at C:/strawberry/perl/site/lib/Spreadsheet/XLSX.pm line 279.
代码:
# CHECK FOR VALID FILE
my $filename = shift or die "ERROR: File not received. Please try again.";
#DEBUG
print $filename;
# READ EXCEL FILE
my $workbook = Spreadsheet::XLSX->new($filename);
您无法使用 Spreadsheet:XLSX 打开 CSV 或 XLS 文件。顾名思义,它适用于压缩 XML 文件的 XLSX 文件。如果它无法打开这些文件,那么您的文件可能已损坏
由于您似乎在 Windows 上,如果您在该系统上安装了 Excel,您可以选择使用 Win32::OLE 模块直接控制 Excel 到 read/write Excel 个文件。
对于 CSV 文件,直接解析内容可能更容易,就好像它是文本文件一样,或者使用类似 Text::CSV 模块的东西。
哇,这么简单的事情花了很长时间。
解决方案是在 "binary mode" 中打开文件,因为我使用 Windows 来区分文本和二进制数据。
http://perldoc.perl.org/functions/binmode.html
use CGI qw(:standard);
# upload file
my $upload_filehandle = upload("filename");
# open the uploaded file
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
# use binary mode (for Excel files on Windows)
binmode UPLOADFILE;
我正在尝试使用 Spreadsheet:XLSX
to read Excel files, but I get this error message with CSV, XLS, and XLSX file uploads. I had it working previously with Spreadsheet::Read
和 CSV 文件。
代码太简单了,我就是不知道要解决什么问题。
文件上传正确,我有正确的路径和文件名。
错误信息:
Cannot open c:\Website\cgi-bin\bidprocess\files\SEIPA-request-0307123509.xlsx as Zip archive at C:/strawberry/perl/site/lib/Spreadsheet/XLSX.pm line 279.
代码:
# CHECK FOR VALID FILE
my $filename = shift or die "ERROR: File not received. Please try again.";
#DEBUG
print $filename;
# READ EXCEL FILE
my $workbook = Spreadsheet::XLSX->new($filename);
您无法使用 Spreadsheet:XLSX 打开 CSV 或 XLS 文件。顾名思义,它适用于压缩 XML 文件的 XLSX 文件。如果它无法打开这些文件,那么您的文件可能已损坏
由于您似乎在 Windows 上,如果您在该系统上安装了 Excel,您可以选择使用 Win32::OLE 模块直接控制 Excel 到 read/write Excel 个文件。
对于 CSV 文件,直接解析内容可能更容易,就好像它是文本文件一样,或者使用类似 Text::CSV 模块的东西。
哇,这么简单的事情花了很长时间。
解决方案是在 "binary mode" 中打开文件,因为我使用 Windows 来区分文本和二进制数据。
http://perldoc.perl.org/functions/binmode.html
use CGI qw(:standard);
# upload file
my $upload_filehandle = upload("filename");
# open the uploaded file
open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
# use binary mode (for Excel files on Windows)
binmode UPLOADFILE;