![](/img/trans.png)
[英]Merged cells are unmerging on Save, using Spreadsheet::ParseExcel
[英]Error when using Spreadsheet::ParseExcel
編譯以下代碼時出現2個錯誤:
#!/usr/bin/perl
use strict;
use warnings;
use Spreadsheet::ParseExcel;
my $xlsparser = Spreadsheet::ParseExcel->new();
my $xlsbook = $parser->parse('xsl_test.xls');
my $xls = $xls->worksheet(0);
my ( $row_first, $row_last ) = $xls->row_range();
my ( $col_first, $col_last ) = $xls->col_range();
my $csv = '';
for my $row ( $row_first .. $row_last ) { #Step through each row
for my $col ( $col_first .. $col_last ) { #Step through each column
my $cell = $xls->get_cell( $row, $col ); #Get the current cell
next unless $cell;
$csv .= $cell->unformatted(); #Get the cell's raw data -- no border colors or anything like that
if ( $col == $col_last ) {
$csv .= "\n"; #Make a new line at the end of the row
} else {
$csv .= ",";
}
}
}
錯誤:
global symbol "$parser" requires explicit package name at line 8
global symbol "$xls" requires explicit package name at line 9
我從http://www.ehow.com/how_7352636_convert-xls-csv-perl.html獲得了上述代碼,並使用以下代碼安裝了excel模塊: cpan Spreadsheet::ParseExcel Spreadsheet::XLSX Spreadsheet::Read
是什么導致錯誤?
這些錯誤表示您使用的是strict
,但是您並未在my
腳本中聲明一些變量。 例如,您聲明了$xmlprser
,但是隨后嘗試使用未聲明的$parser
。 您復制的代碼有錯誤。
獲得代碼的更好的地方是源代碼本身: Spreadsheet :: ParseExcel
嘗試:
my $parser = Spreadsheet::ParseExcel->new();
my $xlsbook = $parser->parse('xsl_test.xls');
my $xls = $xlsbook->worksheet(0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.