#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $t0 = Benchmark->new;
#use Spreadsheet::WriteExcel;
use Excel::Writer::XLSX;
my $filePath = 'D:\work\test.txt';
open(FILE,"$filePath");
my $workbook = Excel::Writer::XLSX->new('tab.xls');
my $worksheet = $workbook->add_worksheet();
my $row = 0;
while (my $line = <FILE>){
chomp($line);
# Split on single tab
#print "$line\n";
my @Fld = split('\|', $line);
my $cnt = scalar(@Fld);
my $col = 0;
while ($cnt>= $col){
$worksheet->write_string($row, $col, $Fld[$col]);
$col++;
}
$row++;
}
my $t1 = Benchmark->new;
my $td = timediff($t1, $t0);
print "the code took:",timestr($td),"\n";
it giving me this error --- Use of uninitialized value $str in hash element while i am using $worksheet->write_string($row, $col, $Fld[$col]); its working fine with write subroutine $worksheet->write($row, $col, $Fld[$col]); |