The code isn't working because you re-open the TABFILE at every new sheet. Another problem is that exiting the while loop with last discards a line of data just read in from TABFILE.
Try this;
poj#!/usr/bin/perl -w use strict; use Spreadsheet::WriteExcel; my $MAX_ROW = 9; my $workbook = Spreadsheet::WriteExcel->new('tabnew.xls'); my $worksheet = $workbook->add_worksheet(); my $row = 0; my $sheetno = 1; print "Sheet $sheetno\n"; open (TABFILE, 't.txt') or die "t.txt: $!"; while (<TABFILE>) { if ($row > $MAX_ROW){ $worksheet = $workbook->add_worksheet(); ++$sheetno; $row = 0; print "Sheet $sheetno\n"; } chomp; my @Fld = split(','); print "Row $row = @Fld\n"; $worksheet->write_row($row, 0, \@Fld); $row++; }
In reply to Re^2: CONVERTING CSV TO XLS
by poj
in thread CONVERTING CSV TO XLS
by mayanks94
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |