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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The code you show should work. I fleshed it out to a working example(*) and it shows the correct MAX and AVERAGE for valid cell ranges. If the cell range is empty then the result will be zero/#DIV0! like the corresponding Excel formula:

#!/usr/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; use Spreadsheet::WriteExcel::Utility; my $workbook = Spreadsheet::WriteExcel->new( 'test.xls' ); my $worksheet = $workbook->add_worksheet(); $worksheet->write( 'B2', 3 ); $worksheet->write( 'B3', 5 ); my @cols = ( 1, 2 ); my $row = 3; my $i = 1; for ( @cols ) { my $s = xl_rowcol_to_cell( 1, $i ); my $e = xl_rowcol_to_cell( $row - 1, $i ); my $range = "$s:$e"; print "$i:Range:$range\n"; $worksheet->write_formula( $row, $i, '=MAX(' . $range . ') +' ); $worksheet->write_formula( $row + 1, $i, '=AVERAGE(' . $range +. ')' ); $i++; } __END__

Spreadsheet::WriteExcel does sometimes mis-parse complex formulae resulting in an invalid 0 result. However, that isn't the case here.

* You should have done this when asking the questing. It only takes a few extra lines of code.

--
John.


In reply to Re: WriteExcel and formulas by jmcnamara
in thread WriteExcel and formulas by rohit_raghu

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-19 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found