MissPerl has asked for the wisdom of the Perl Monks concerning the following question:
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();
Also, is it possible to achieve what I want?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.
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Spreadsheet::WriteExcel; combining xls into one
by thanos1983 (Parson) on Jun 08, 2017 at 10:15 UTC | |
by MissPerl (Sexton) on Jun 12, 2017 at 10:24 UTC | |
|
Re: Spreadsheet::WriteExcel; combining xls into one
by Anonymous Monk on Jun 09, 2017 at 05:04 UTC | |
by MissPerl (Sexton) on Jun 12, 2017 at 10:26 UTC | |
by poj (Abbot) on Jun 12, 2017 at 11:15 UTC | |
by MissPerl (Sexton) on Jun 13, 2017 at 06:27 UTC | |
by poj (Abbot) on Jun 13, 2017 at 07:20 UTC | |
by Anonymous Monk on Nov 13, 2019 at 05:36 UTC |