reaper9187 has asked for the wisdom of the Perl Monks concerning the following question:
Everything works perfectly in the command prompt workspace. Now comes the problem.print "$cell->value()";
it does seem to perform the checks on the numeric values correctly, but it does not print the actual name of the corresponding value(eg Name1, name2,etc as in the below eg). The excel file is in this format:$txt->insert('end',"$worksheet->{Cells}[$row][$col]->{Val}");
#!/usr/local/bin/perl use Tk; # Main Window my $mw = new MainWindow; $mw->Frame(-background => 'red')->pack(-ipadx =>50, -side => "left", - +fill => "y"); #Making a text area my $txt = $mw -> Scrolled('Text',-width => 150, height => 40, -scrollb +ars=>'e', -font => "fixed 8 bold" ) -> pack (); $txt->insert('end', ""); #Declare that there is a menu my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); #The Main Buttons my $file = $mbar -> cascade(-label=>"File", -underline=>0, -tearoff => + 0); my $open = $mbar -> cascade(-label=>"Open", -underline=>0, -tearoff => + 0); my $tool= $mbar -> cascade(-label =>"Tools", -underline=>0, -tearoff = +> 0); my $parser = $mbar -> cascade(-label =>"RL ", -underline=>0, -tearoff +=> 0); my $help = $mbar -> cascade(-label =>"Help", -underline=>0, -tearoff = +> 0); ## File Menu ## $file -> command(-label => "Home", -underline=>0, -command=> \&home ); $file -> command(-label => "Check ", -underline=>0, -command=> \&define ); $file -> checkbutton(-label =>"faults", -underline => 0, -command => \&faults); $file -> separator(); $file -> command(-label =>"Exit", -underline => 1, -command => sub { exit } ); ##Open Menu## $open->command( -label => 'Open', -underline => 0, -command => \&f_ope +n ); $open->command( -label => 'Save', -underline => 0, -command => \&f_sav +e ); $open->separator; $open->command( -label => 'Exit', -underline => 1, -command => sub{ +exit} ); ## Tools Menu ## $tool -> command(-label => "Ne", -underline=>0, -command=> \&nwplan ); $tool -> command(-label => " ", -underline=>0, -command=> \&optimize ); $tool -> separator(); ## Parse Menu ## $parser -> command(-label => "P", -underline=>0, -command=> \&parse ); ## Help Menu ## $help -> command(-label => "About", -underline=>0, -command=> \&help ); MainLoop; sub help { my ($opt) = @_; $mw->messageBox(-message=>"This function is not available yet"); } Mainloop; sub f_open { my $filename = $mw->getOpenFile( -title => 'Open File:', -defaultextension => '.xls', -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"; } for my $worksheet ( $workbook->worksheet(1) ) { my ( $row_min, $row_max ) = $worksheet->row_range(); my ( $col_min, $col_max ) = $worksheet->col_range(); for my $row ( $row_min .. 20 ) { for my $col ( $col_min .. $col_max ) { my $cell = $worksheet->get_cell( $row, $col ); next unless $cell; print "Row, Col = ($row, $col)\n"; print "Value = ", $cell->value(), "\n"; print "\n"; $txt->insert('end',"$row:$col----$worksheet->{Cells +}[$row][$col]->{Val}\n"); } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Excel Text parsing problem
by grizzley (Chaplain) on Nov 08, 2012 at 08:11 UTC | |
by reaper9187 (Scribe) on Nov 08, 2012 at 08:37 UTC | |
by grizzley (Chaplain) on Nov 08, 2012 at 09:01 UTC | |
by reaper9187 (Scribe) on Nov 08, 2012 at 09:47 UTC | |
by grizzley (Chaplain) on Nov 08, 2012 at 10:39 UTC | |
|
Re: Excel Text parsing problem
by Anonymous Monk on Nov 08, 2012 at 09:40 UTC | |
by reaper9187 (Scribe) on Nov 08, 2012 at 09:52 UTC | |
by reaper9187 (Scribe) on Nov 08, 2012 at 09:58 UTC | |
by reaper9187 (Scribe) on Nov 08, 2012 at 10:11 UTC |