my $source = $book->add_worksheet($source);

This line suggests you are getting confused between the source and the target. Try using more descriptive variable names for each workbook/worksheet. Try

#!/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 ); } } }
poj

In reply to Re^3: Spreadsheet::WriteExcel; combining xls into one by poj
in thread Spreadsheet::WriteExcel; combining xls into one by MissPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.