in reply to Spreadsheet::WriteExcel; combining xls into one

Hello MissPerl,

Well I just read your question and I remembered that maybe 5 - 6 years ago that another monk asked the same question writing after parsing.

Take a look on the question but I spend some time and I created a script that it was merging excel files into one here is the link Re^2: writing after parsin.

Let me know if it works, alternatively I can spend some time and debug it.

Update: I tested your code and you have many errors.

Let's fix them:

use warning; # needs to be use warnings; my $path = '/abc'; my $te = "$abc/texas"; # I assume you mean $path instead of $abc? my $mi = "$abc/michigan"; I assume you mean $path instead of $abc? my $ha = "$abc/hawaii"; I assume you mean $path instead of $abc? my $fl = "$abc/florida"; I assume you mean $path instead of $abc? my $ke = "$abc/kentucky"; I assume you mean $path instead of $abc? my $filename = "path/one.xls"; # needs to be my $filename = "$path/one +.xls"; my $excl = Spreadsheet::WriteExcel->new($filename) or die "Cannot create new Excel file: $!" unless defined $excl; # thi +s will not work my $workbook = Spreadsheet::WriteExcel->new('protected.xls'); # from +module documentation (notice the ";" here) die "Problems creating new Excel file: $!" unless defined $workbook; # + from module documentation # add the following after the part my $book = $parser->parse($source); for my $source ( '$te/te.xls', '$mi/mi.xls', # all files need to be de +fined with double quotes (e.g. "$te/te.xls") '$ha/ha.xls', '$fl/fl.xls', # with single quotes will not wor +k '$ke/ke.xls' ){ my $book = $parser->parse($source); if ( !defined $book ) { die $parser->error(), ".\n"; }

Update2: I also noticed:

if ($source =~ /1/) { $file = $excl->add_worksheet('Texas'); }

This will never work, you are invoking a method from Spreadsheet::WriteExcel/add_worksheet($sheetname, $utf_16_be) but the object that you are using is from Spreadsheet::ParseExcel/new(). Change object use the one that is for writing.

After fixing all the errors give it another try.

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Spreadsheet::WriteExcel; combining xls into one
by MissPerl (Sexton) on Jun 12, 2017 at 10:24 UTC
    Hi Thanos, thank you for your help! the code is now clean with errors.

    However I'm still not getting what I want.

    Could you lead me to the right direction?

    I have put some updated info in the question.

    Thank you !!