我有一个制表符分隔的文件,我想写入Excel。我使用过Spreadsheet :: WriteExcel,但第一次运行只会在Excel中写入99行,然后在第100行中途停止。我已经检查了tab-del .txt,没有额外的空格或新行。 .txt文件中的所有行都有14或15个值,打印输出print $row size
显示为14/15,最后一行显示6
。当我再次运行它时,它显示剩余的行,但也显示第二次运行的其他行。有人可以帮助我查看我的代码以查看问题所在吗?
open(FIRST, '>>', $first_file) || die "";
#create tab delimted file
close(FIRST);
open(SECOND, $first_file) || die "cannot open $ind_output to write to excel";
my $xl_row_num = 0;
my $xl_file = "tab_ann.xls";
my $xl = Spreadsheet::WriteExcel->new($xl_file);
my $txt_xl = $xl -> add_worksheet();
my $format = $xl -> add_format();
$format->set_color('red');
while(my $line = <SECOND>){
#create an array containing each value the current line
my @data = split("\t", $line);
#my $size = scalar(@data);
#print "row size:\t".$size."\n";
print "row rum:\t".$xl_row_num."\n";
#Write each value in array in separate cell in a single row.
for(my $col=0; $col < $size+1; $col++){
$txt_xl->write($xl_row_num, $col, $data[$col], $format);
}
@data=();
$xl_row_num++;
}
close SECOND;