Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I tried a modified version of the example code given in It works very well and now I am trying to understand it.

I am not sure what these two lines are doing.

$sheet -> {MaxRow} ||= $sheet -> {MinRow}; $sheet -> {MaxCol} ||= $sheet -> {MinCol};

My guess is that if MaxRow or MaxCol are undefined then they are set to equal MinRow or MinCol respectfully. If that is true then under what circumstances is MAX not defined?

Also, I Data::Dumper::Simple'd $excel and it appears MinCol and MaxCol does not vary by row i.e., it is set once for each worksheet. So why execute it on each row? Or did I read the dump incorrectly?

Following is the code I ran:

use strict; use warnings; use Data::Dumper::Simple; use Spreadsheet::XLSX; # use Text::Iconv; # my $converter = Text::Iconv -> new ("utf-8", "windows-1251"); # Text::Iconv is not really required. # This can be any object with the convert method. Or nothing. # my $excel = Spreadsheet::XLSX -> new ('test.xlsx', $converter); my $excel = Spreadsheet::XLSX -> new ($ARGV[0]); print Dumper($excel); foreach my $sheet (@{$excel -> {Worksheet}}) { printf("Sheet: %s\n", $sheet->{Name}); $sheet -> {MaxRow} ||= $sheet -> {MinRow}; foreach my $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) { $sheet -> {MaxCol} ||= $sheet -> {MinCol}; foreach my $col ($sheet -> {MinCol} .. $sheet -> {MaxCol}) { my $cell = $sheet -> {Cells} [$row] [$col]; if ($cell) { printf("( %s , %s ) => %s\n", $row, $col, $cell -> {Va +l}); } } } }

Thanks in advance!

In reply to What is the purpose of '||=' in the example code for Spreadsheet::XLSX by vt220

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (3)
    As of 2018-06-22 04:02 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (121 votes). Check out past polls.