Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Parsing multiple excel files in perl

by reaper9187 (Scribe)
on Oct 15, 2012 at 10:25 UTC ( #999059=note: print w/ replies, xml ) Need Help??


in reply to Re: Parsing multiple excel files in perl
in thread Parsing multiple excel files in perl

Thanks for the reply

This part of the application is a small portion of the entire software package i'm working on. Haven't written the code yet for this . Was looking for some kind of a headstart

I have developed a parser for a single workbook for another section of the package but couldn't understand the process for multiple file handles.


Comment on Re^2: Parsing multiple excel files in perl
Re^3: Parsing multiple excel files in perl
by marto (Chancellor) on Oct 15, 2012 at 10:29 UTC

    "I have developed a parser for a single workbook"

    So are not using a module such as Spreadsheet::ParseExcel or Win32::OLE and have hand rolled a solution? Again, if you don't bother to show us what you're doing and what you're having problems with you make it harder to help, and drawing information piecemeal gets boring after a while.

    Read and understand How do I post a question effectively?.

      I have mentioned in the post itself that i am using the Spreadsheet::ParseExcel module.
      If you insist on having a look at the code: (This is jus a part of the entire code and works on just . I need to integrate multiple modules similar to the one below)

      sub push_button2 { my $filename = $mw->getOpenFile( -title => 'Open File:', -defaultextension => '.xslx', -initialdir => '.' ); warn "Opened $filename\n"; open(MYFILE,$filename); # Text::Iconv is not really required. # This can be any object with the convert method. Or nothing. use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse($filename); if ( !defined $workbook ) { die $parser->error(), ".\n"; } $txt -> delete('1.0', 'end'); for my $worksheet ( $workbook->worksheets(0) ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. $row_max ) { for my $col(8) { my $cell = $worksheet->get_cell( $row, $col ); next unless $cell; if($worksheet->{Cells}[$row][8]->{Val} > 2) { if($worksheet->{Cells}[$row][21]->{Val} >75) { $txt -> insert('end', " $worksheet->{Cells}[$row][ +1]->{Val}\n"); $txt -> insert('end', "\n REASON: Other\n"); $txt -> insert('end', " DIAGNOSIS: Check the fault + definition\n\n"); } elsif($worksheet->{Cells}[$row][13]->{Val} > 50) { $txt -> insert('end', " $worksheet->{Cells}[$row][ +1]->{Val}\n"); $txt -> insert('end', " \nREASON: Low Signal Stren +gth\n"); $txt -> insert('end', " DIAGNOSIS: Check the fault + definition for troubleshooting\n\n"); } elsif($worksheet->{Cells}[$row][16]->{Val} >50) { $txt -> insert('end', " $worksheet->{Cells}[$row][ +1]->{Val}\n"); $txt -> insert('end', " \nREASON: Bad Quality Upli +nk/Downlink\n"); $txt -> insert('end', " DIAGNOSIS: Check the fault + definition for troubleshooting\n\n"); } } else {next;} } } close(MYFILE); } }

        "I have mentioned in the post itself that i am using the Spreadsheet::ParseExcel module."

        Actually, you updated your post after two people had to draw this information out of you, we wouldn't have had to ask otherwise.

      I apologize for the mistakes in the post. Its my first time here actually I have updated the post and the pasted the code. You can have a look at it now
      I'm not particularly proud of this code but this is as far as i could get using multiple file handles
      sub push_button4 { sub push_button1(); $txt->insert('end',"Opened $filename1\n"); sub push_button2(); $txt->insert('end',"Opened $filename2\n"); sub push_button3(); $txt->insert('end',"Opened $filename3\n"); open($filename1,$filename2); my $parser = Spreadsheet::ParseExcel->new(); my $workbook1 = $parser->Parse($filename1) or die $parser->error; my $workbook2 = $parser->Parse($filename2) or die $parser->error; foreach $worksheet($workbook1->worksheet(2),$workbook2->worksheet(2)) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( 0..10 ) { for my $col ( $col_min .. $col_max ) { $txt->insert('end',"$worksheet->{Cells}[$row][1]->{Val +} \n") } } } }
      Please suggest improvements
        Please suggest improvements

        Just a quick observation: In this part of the code:

        sub push_button4 { sub push_button1(); $txt->insert('end',"Opened $filename1\n"); sub push_button2(); $txt->insert('end',"Opened $filename2\n"); sub push_button3(); $txt->insert('end',"Opened $filename3\n"); ...

        I’m guessing you meant to call subroutines push_button1, push_button2, and push_button3, in which case you need to remove the three occurrences of sub. In its current form, the code is simply declaring that each of these subroutines is prototyped to take no arguments (which is probably wrong, and is certainly unnecessary) — but it isn’t calling (i.e., invoking) them.

        Hope that helps,

        Athanasius <°(((><contra mundum

      Hi there,
      Thank you for replying.
      Yes there is a prototype mismatch in the subroutine.
      The three subroutines are basically used to input the multiple files from the user using the open dialog box and pushbutton. Once the user enters the files, these filenames are then passed as arguments to parser which then parses through the multiple files simultaneously.
      Can you suggest a better way to do this ??. the three subroutines are similar and a sample code is as follows:
      sub push_button1 { $filename1 = $mw->getOpenFile( -title => 'Open File:', -defaultextension => '.xslx', -initialdir => '.' ); $ent -> insert('end',"$filename1"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999059]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-09-23 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (219 votes), past polls