Regex 追加数据时Excel SaveParser中出现问题
我想使用perl脚本在excel文件中创建并附加一些数据。正如许多论坛链接所建议的,我参考了模块链接上提供的示例代码。电子表格创建成功,没有问题 但是,然后我使用第二个脚本将一些数据附加到现有文件中。我使用模块并使用上提供的示例代码。以下是我的代码,与网站上提供的代码完全相同:Regex 追加数据时Excel SaveParser中出现问题,regex,excel,perl,file,append,Regex,Excel,Perl,File,Append,我想使用perl脚本在excel文件中创建并附加一些数据。正如许多论坛链接所建议的,我参考了模块链接上提供的示例代码。电子表格创建成功,没有问题 但是,然后我使用第二个脚本将一些数据附加到现有文件中。我使用模块并使用上提供的示例代码。以下是我的代码,与网站上提供的代码完全相同: #!/usr/bin/perl use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; use Spreadsheet::W
#!/usr/bin/perl
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
use Spreadsheet::WriteExcel;
# Open an existing file with SaveParser
my $parser = Spreadsheet::ParseExcel::SaveParser->new();
my $template = $parser->Parse('perl.xls');
# Get the first worksheet.
my $worksheet = $template->worksheet(0);
my $row = 0;
my $col = 0;
# Overwrite the string in cell A1
$worksheet->AddCell( $row, $col, 'New string' );
# Add a new string in cell B1
$worksheet->AddCell( $row, $col + 1, 'Newer' );
# Add a new string in cell C1 with the format from cell A3.
my $cell = $worksheet->get_cell( $row + 2, $col );
my $format_number = $cell->{FormatNo};
$worksheet->AddCell( $row, $col + 2, 'Newest', $format_number );
# Write over the existing file or write a new file.
$template->SaveAs('newfile.xls');
但是,我得到了以下错误:
Unknown method: Spreadsheet::WriteExcel::Format::set_hidden at <path_to_SaveParser.pm> line 72.
Shebang操作符(
#!
)路径似乎没有任何问题,因为它与我在创建excel文件时使用的路径相同。任何人都可以提供一些关于可能出现的问题的建议吗?我在ubuntu上使用perl 5.20.1时,代码很有用。我使用cpan安装了电子表格::WriteExcel
和电子表格::ParseExcel
在这里检查您的OS/Perl版本组合:OS是SUSE Linux,Perl版本是5.014001。但是,由于写入excel文件的过程非常顺利,我对版本问题几乎没有什么怀疑。您运行的是哪个版本的ParseExcel?命令perldoc-m电子表格::ParseExcel | grep version
给出的版本是:our$version='0.59'代码>在ubuntu上使用Perl5.20.1的代码对我有效。我使用cpan安装了电子表格::WriteExcel
和电子表格::ParseExcel
在这里检查您的OS/Perl版本组合:OS是SUSE Linux,Perl版本是5.014001。但是,由于写入excel文件的过程非常顺利,我对版本问题几乎没有什么怀疑。您运行的是哪个版本的ParseExcel?命令perldoc-m电子表格::ParseExcel | grep version
给出的版本是:our$version='0.59'代码>
sub SaveAs($$){
my ($oBook, $sName)=@_;
# Create a new Excel workbook
my $oWrEx = Spreadsheet::WriteExcel->new($sName);
my %hFmt;
my $iNo = 0;
my @aAlH = ('left', 'left', 'center', 'right', 'fill', 'justify', 'merge', 'equal_space');
my @aAlV = ('top' , 'vcenter', 'bottom', 'vjustify', 'vequal_space');
foreach my $pFmt (@{$oBook->{Format}}) {
my $oFmt = $oWrEx->addformat(); # Add Formats
unless($pFmt->{Style}) {
$hFmt{$iNo} = $oFmt;
my $rFont = $pFmt->{Font};
$oFmt->set_font($rFont->{Name});
$oFmt->set_size($rFont->{Height});
$oFmt->set_color($rFont->{Color});
$oFmt->set_bold($rFont->{Bold});
$oFmt->set_italic($rFont->{Italic});
$oFmt->set_underline($rFont->{Underline});
$oFmt->set_font_strikeout($rFont->{Strikeout});
$oFmt->set_font_script($rFont->{Super});
$oFmt->set_hidden($rFont->{Hidden}); #LINE 72 !!!
$oFmt->set_align($aAlH[$pFmt->{AlignH}]);
$oFmt->set_align($aAlV[$pFmt->{AlignV}]);
if($pFmt->{Rotate}==0) {
$oFmt->set_rotation(0);
}
#....