这是我的第一次尝试,我正在尝试掌握使用Excel :: Writer :: XLSX的基础知识。我似乎无法完全编译我的脚本。
#!C:\Perl\bin
#excel::writer attempt
#allows IR-Serial-Parts tracking
use strict;
use warnings;
use POSIX qw(strftime);
use Excel::Writer::XLSX;
my $ref = strftime '%Y-%m-%d', locatime(); #create the datestamp
my $file = "$ref.xlsx";
my $workbook = Excel::Writer::XLSX->new('$file'); #declare it outside of if loop preventing original issue.
#if(-e $file){
# my $workbook = Excel::Writer::XLSX->open('$file'); #open existing excel file
#}
#else{
# my $workbook = Excel::Writer::XLSX->new('$file'); #open new Excel if the date on comp has changed
#}
$worksheet = $workbook->add_worksheet("Tracking");
$worksheet->write( 'A1', 'Hi Excel!');
我什至不需要做任何事情,我只是想测试对电子表格中单元格的写入,而我什至无法做到这一点。我觉得我现在正在努力。这是外壳返回的内容。
Global symbol "$worksheet" requires explicit package name at writexcel.pl line 20.
Global symbol "$workbook" requires explicit package name at writexcel.pl line 20
.
Global symbol "$worksheet" requires explicit package name at writexcel.pl line 21.
Execution of writexcel.pl aborted due to compilation errors.
Press any key to continue . . .
现在,原来的问题已经解决。
Undefined subroutine &main::locatime called at writexcel.pl line 11.
Press any key to continue . . .
我的新错误。我认为这可能与strftime有关,但我不太确定。
尝试在$workbook
循环外声明变量。另外,在使用时,strict
您需要$worksheet
使用声明my
:
use strict;
use warninigs;
my $workbook;
if(-e $file){
$workbook = Excel::Writer::XLSX->open($file);
}
else{
$workbook = Excel::Writer::XLSX->new($file);
}
my $worksheet = $workbook->add_worksheet('Tracking');
$worksheet->write( 'A1', 'Hi Excel!');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句