Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

parsing excel with 5 levels of indentations

by leha (Novice)
on Oct 03, 2013 at 07:49 UTC ( #1056732=perlquestion: print w/replies, xml ) Need Help??
leha has asked for the wisdom of the Perl Monks concerning the following question:

hello monks
i have excel file with 5 levels of indentations so i guess i need Spreadsheet::ParseExcel::Format
but when i'm trying $format->{Indent} (just like in synopsis) perl says: 'Global symbol "$format" requires explicit package name'
i was trying different ways, also 'Spreadsheet::ParseExcel::Format->new()' and others, but still no success
what is right synopsis or is there other ways to parse indentations from xls-files ?
maybe some binary? (xlhtml and xls2csv don't care about indents at all :( )

solution from John McNamara:

#!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse('Book1.xls'); if ( !defined $workbook ) { die $parser->error(), ".\n"; } for my $worksheet ( $workbook->worksheets() ) { 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; my $format = $cell->get_format(); print "Row, Col = ($row, $col)\n"; print "Value = ", $cell->value(), "\n"; print "Indent = ", $format->{Indent}, "\n"; print "\n"; } } } __END__

Replies are listed 'Best First'.
Re: parsing excel with 5 levels of indentations
by kcott (Chancellor) on Oct 03, 2013 at 08:05 UTC

    G'day leha,

    Welcome to the monastery.

    Your main problem is that you're not declaring $format. The code you want would look something like this:

    my $format = ... ... $format->{Indent} ...

    Without having a better idea of your code, I can't be more specific than that.

    You appear to making reference to code in the Spreadsheet::ParseExcel::Format documentation: it doesn't contain any so perhaps you could clarify that.

    For any follow-up questions, please use the guidelines in "How do I post a question effectively?".

    -- Ken

      i know about declaring $format
      i just don't know how :\
      my code is like this:
      open(F,">$s{path}/perl.output"); my $parser = Spreadsheet::ParseExcel->new(); my $workbook = $parser->parse("$s{path}/$s{file}"); if ( !defined $workbook ) {die $parser->error(), ".\n"} for my $worksheet ( $workbook->worksheets() ) { 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) Value = ", $cell->value(),"\n"; } } } close F;
      and here i need to put indent somewhere somehow have this explanation:
      The C<Spreadsheet::ParseExcel::Format> class has the following propert +ies: =head2 Format properties $format->{Font} $format->{AlignH} $format->{AlignV} $format->{Indent} $format->{Wrap} $format->{Shrink} $format->{Rotate} $format->{JustLast} $format->{ReadDir} $format->{BdrStyle} $format->{BdrColor} $format->{BdrDiag} $format->{Fill} $format->{Lock} $format->{Hidden} $format->{Style} These properties are generally only of interest to advanced users. Cas +ual users can skip this section.
      not much so i still seeking wisdom about parsing indentations levels from xls

        my $cell = $worksheet->get_cell( $row, $col );


        and here i need to put indent somewhere somehow

        I haven't tried any of this, but continuing with the documentation of Spreadsheet::ParseExcel::Cell you should be able to test what my $format = $cell->get_format(); print $format->{Indent}, "\n"; is returning and build on that information.

        Cheers, Sören

        Créateur des bugs mobiles - let loose once, run everywhere.
        (hooked on the Perl Programming language)

Re: parsing excel with 5 levels of indentations ( JMCNAMARA/Spreadsheet-ParseExcel-0.59/sample/ )
by Anonymous Monk on Oct 03, 2013 at 07:59 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1056732]
Approved by kcott
Front-paged by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-05-23 05:42 GMT
Find Nodes?
    Voting Booth?