Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Excel::Writer::XLSX 0 byte outfile

by fionbarr (Friar)
on Nov 14, 2014 at 20:18 UTC ( [id://1107246]=note: print w/replies, xml ) Need Help??


in reply to Excel::Writer::XLSX 0 byte outfile

the scope of '$text_format' is not available to the worksheet->write line. This worked for me:
use strict; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new( 'mytest.xlsx' ); my $worksheet = $workbook->add_worksheet( 'testsheet' ); my $text_format = $workbook->add_format( bold => 1, italic => 1, color => 'red', size => 18, font => 'Lucida Calligraphy' ); $worksheet->write( 'A2', "Text" ); $worksheet->write( 'B3', "Hello Excel", $text_format ); $worksheet->write( 'B8', "Hello Excel"); $workbook->close; __END__

Replies are listed 'Best First'.
Re^2: Excel::Writer::XLSX 0 byte outfile
by Corion (Patriarch) on Nov 15, 2014 at 09:14 UTC

    the scope of '$text_format' is not available to the worksheet->write line.

    Why do you say that? Can you please explain how scope works and why $text_format would be out of scope for the worksheet->write line?

Re^2: Excel::Writer::XLSX 0 byte outfile
by doc1623 (Novice) on Nov 14, 2014 at 22:15 UTC
    Thanks but I'm trying to do things in subroutines. I have a variable declared globally but it's instantiated and asigned only in a subroutine. I then have a seperate write subroutine. I shoudn't have to pass the worksheet, should I?

      If you want to use subroutines (as you should) then try passing parameters into your subroutines. The following code works for me. (Read: It does not produce any warnings or errors and the Excel file is properly formatted).

      #!/bin/env perl use strict; use warnings; use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new( 'mytest.xlsx' ); my $worksheet = $workbook->add_worksheet( 'testsheet' ); write_me( $workbook, $worksheet ); sub write_me { my ( $workbook, $worksheet ) = @_; my $text_format = $workbook->add_format( bold => 1, italic => 1, color => 'red', size => 18, font => 'Lucida Calligraphy' ); my $result = $worksheet->write( 'A2', "Text" ); print "my result = $result\n"; $worksheet->write( 'B3', "Hello Excel", $text_format ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1107246]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found