Hi PerlMonks! Excited to be here.

I'm currently trying to put the multiple .xls files(5, sometimes 20) into (one.xls) (as worksheets in it).

Then I will send it out as attachment in email.

As Idk how to put the sheetname according to my xls filename, so I rename the sheets in the code.

Here is what I've got after reviewing CPAN forum + available resources on the Internet.

Updates

#!/usr/bin/perl use strict; use warning; use Spreadsheet::WriteExcel; use Spreadsheet::ParseExcel; my $path = '/abc'; my $te = "$path/texas"; my $mi = "$path/michigan"; my $ha = "$path/hawaii"; my $fl = "$path/florida"; my $ke = "$path/kentucky"; my $excl = Spreadsheet::WriteExcel->new("$path/one.xls"); die "Cannot create new Excel file: $!" unless defined $excl; my $parser = new Spreadsheet::ParseExcel; for my $source ( "$te/te.xls", "$mi/mi.xls", "$ha/ha.xls", "$fl/fl.xls", "$ke/ke.xls" ){ my $book = $parser->parse($source); if ( !defined $book ) { die $parser->error(), ".\n"; } my $file; my $source = $book->add_worksheet($source); if ($source =~ /1/) { $file = $excl->add_worksheet('TX'); } elsif ($source =~ /2/) { $file = $excl->add_worksheet('MI'); } elsif ($source =~ /3/) { $file = $excl->add_worksheet('HI'); } elsif ($source =~ /4/) { $file = $excl->add_worksheet('FL'); } elsif ($source =~ /5/) { $file = $excl->add_worksheet('KY'); } my $all = $file; for my $parse_worksheet ( $excl->source() ) { 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; $all->write( $row , $col, $cell->unformatted ); } } } } $excl->close();
The code is now clean without errors. I have tried to export the new file, but the excel file has only one s +heet with Empty data. sad I did tried to export one of the xls file, and yes Im getting the one +sheet with contents. Can anyone please help me out? I'm still new to Perl, so I don't have any idea what I did wrong in th +e code.
Also, is it possible to achieve what I want?

Is there anything else wrong in the script that will make it not worked?

I'm working this in Linux Perl 5.8.8. Thanks in advanced for any advice.

In reply to 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.