in reply to Re^2: Spreadsheet::WriteExcel; combining xls into one
in thread Spreadsheet::WriteExcel; combining xls into one
This line suggests you are getting confused between the source and the target. Try using more descriptive variable names for each workbook/worksheet. Try
poj#!/usr/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; my $path = '/abc'; my $output = $path.'/one.xls'; my $wb_target = Spreadsheet::WriteExcel->new($output) or die "Cannot create new Excel file: $!";; my $parser = new Spreadsheet::ParseExcel; my @states = qw(texas michigan hawaii florida kentucky); for my $state ( @states ){ my $abbr = substr($state,0,2); print "Creating sheet $abbr in $output\n"; my $ws_target = $wb_target->add_worksheet(uc $abbr); my $source = "$path/$state/$abbr.xls"; print "Copying $source\n"; my $wb_source = $parser->parse($source) or die $parser->error(); ws_copy($wb_source->worksheet(0),$ws_target); } $wb_target->close(); sub ws_copy { my ($source,$target) = @_; my ( $row_min, $row_max ) = $source->row_range(); my ( $col_min, $col_max ) = $source->col_range(); for my $row ( $row_min .. $row_max ) { for my $col ( $col_min .. $col_max ) { my $cell = $source->get_cell( $row, $col ); next unless $cell; $target->write( $row , $col, $cell->unformatted ); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Spreadsheet::WriteExcel; combining xls into one
by MissPerl (Sexton) on Jun 13, 2017 at 06:27 UTC | |
by poj (Abbot) on Jun 13, 2017 at 07:20 UTC |