Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Excel Text parsing problem

by reaper9187 (Scribe)
on Nov 08, 2012 at 08:37 UTC ( #1002838=note: print w/replies, xml ) Need Help??

in reply to Re: Excel Text parsing problem
in thread Excel Text parsing problem

Here you go
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 .. $row_max ) { 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"); } } }
When the print line is executed it gives an output type: Row, Col = (8, 1) Value = LWSHI1C Row, Col = (8, 2) Value = 900 Row, Col = (8, 4) Value = 2 Row, Col = (8, 5) Value = Row, Col = (8, 6) Value = 3
But the text line gives an output as below
8:1----8:2---- 8:3---- 8:4---- 8:7----8:8----
For the same code, the text line is not able to read the name (LWSHI1C) or any of the above values, it only reads certain columns .. Dont know why...

Replies are listed 'Best First'.
Re^3: Excel Text parsing problem
by grizzley (Chaplain) on Nov 08, 2012 at 09:01 UTC


    I've replaced worksheet(1) with worksheet(0) (because had data in first worksheet) and replaced $txt->insert with print 'end: ', "$row:$col----$worksheet->{Cells}[$row][$col]->{Val}\n"; statement and got proper results:

    c:\d\test> Book1.xls Row, Col = (7, 0) Value = LWSHI1C end: 7:0----LWSHI1C Row, Col = (7, 1) Value = 900 end: 7:1----900 Row, Col = (7, 3) Value = 2 end: 7:3----2 Row, Col = (7, 5) Value = 3 end: 7:5----3 c:\d\test>

    What I can advice in that situation is: please make the same corrections in your script and run it in console to make sure you have data in worksheet(1).

      no i think you didnt understand the problem .. When i use the print command , it only displays the text in the command prompt window ( i have absolutely no problem in doing that evn now)... What i'm looking for is a way to print this text on a text area in a GUI window using perl Tk... I have defined the main widnow , text areas, alignment etc.. i have to display this text on the main GUI window..I use the $txt ->insert command to print it in the text area... but somehow it prints only some of the values(rather than all) ...
        But it's only string! There is no magic in adding text in Tk, so there is no way Tk is doing something wrong (especially that it prints beginning, i.e. "row:col----". Something is wrong with string and the problem is tracking why the string is empty.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002838]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2018-02-17 21:47 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (249 votes). Check out past polls.