Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Comment on

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

What I think is happening is the following:

Your "write" program generates an Excel file containing some formulae.

These formulae never get calculated unless you open the file in Excel and calculate.

If I then use your "read" program to read the file, I get "0.00%" values from the formula cells.

If I first save the spreadsheet in Excel, then the "read" program returns proper values.

My interpretation is that by using Spreadsheet::WriteExcel, formulae will never be calculated, which makes sense as no Excel is present necessarily. Your dilemma now is that you will not have the results from these formulae before you open the spreadsheet in Excel and have it calculated and saved. In which case using "Win32::OLE" would be the better solution. Then Perl would always interact with the spreadsheet through Excel and you can read/write as you like.

I have looked at the module documentation but I found nothing that confirms or contradicts my hypothesis.

Just for completeness, here is my reduced "write" script:

#!/usr/bin/perl use 5.010; use strict; use warnings; use Spreadsheet::WriteExcel; my $WriteWorkbook = Spreadsheet::WriteExcel->new('Write.xls'); my $WriteWorksheet = $WriteWorkbook->add_worksheet('Data'); my $formula = $WriteWorksheet->store_formula('=1-(F1/E1)'); my $f_change = $WriteWorkbook->add_format(); $f_change->set_num_format('0.00%'); for my $row ( 1..4 ) { for my $col ( 4..5 ) { $WriteWorksheet->write($row, $col, rand()); } $WriteWorksheet->repeat_formula($row, 13, $formula, $f_change, 'F1', +'F'.($row+1), 'E1', 'E'.($row+1)); }

and my "read" script:

#!/usr/bin/perl use 5.010; use strict; use warnings; use Spreadsheet::ParseExcel; my $parser = Spreadsheet::ParseExcel->new(); my $ReadWorkbook = $parser->parse('write.xls'); for my $ReadWorksheet($ReadWorkbook->Worksheet('Data')){ my ($row_min, $row_max) = $ReadWorksheet->row_range(); my ($col_min, $col_max) = $ReadWorksheet->col_range(); for my $row($row_min..$row_max){ for my $col ( $col_min..$col_max){ my $cell = $ReadWorksheet->get_cell($row, $col); print "$row,$col,",$cell->value(),"\n" if defined($cell); } } }

In reply to Re^4: Get Cell Value while Reading Excel file and not the formula by hdb
in thread Get Cell Value while Reading Excel file and not the formula by PBegin

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 chilling in the Monastery: (3)
    As of 2018-01-23 08:19 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (241 votes). Check out past polls.