Why not like thus:
ExcelUtil.pm
package ExcelUtil;
use warnings;
use strict;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(writeCell);
sub writeCell {
my ( $obj, $row, $col, $str ) = @_;
$obj->write( $row, $col, $str );
}
1;
testExcel.pl
use warnings;
use strict;
use Spreadsheet::WriteExcel;
use ExcelUtil;
my $wrk_bk = Spreadsheet::WriteExcel->new('sample.xls');
my $wrk_sht = $wrk_bk->add_worksheet('new_sheet');
writeCell( $wrk_sht, 1, $_, "Testing, Row-1, Col-$_" ) for 1..5;
Update:
Why even calling the subroutine within it module like you did in your "ExcelUtil.pm" like this
writeCell(1, 2, "testing, Row-1, Col-2");
With the code shown above you can even do like this:
writeCell( $wrk_sht, $_, 1, "Testing, Row-$_, Col-1" ) for 1..5; And it still works for you.
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author
unknown to me
-
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.