Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Spreadsheet::WriteExcel write failure

by adolpht (Novice)
on Jan 11, 2005 at 10:22 UTC ( [id://421233]=perlquestion: print w/replies, xml ) Need Help??

adolpht has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I've been trying to get the Spreadsheet::WriteExcel write method working for a while without success. I've read *some* of the perldoc, esp:
"So for those of you who prefer to assemble Ikea furniture first and then read the instructions, here are three easy steps:

1. Create a new Excel *workbook* (i.e. file) using "new()".
2. Add a *worksheet* to the new workbook using "add_worksheet()".
3. Write to the worksheet using "write()".

Like this:

use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("perl.xls");$worksheet = + $workbook->add_worksheet();$worksheet->write('A1', "Hi Excel!"); "

I always get the error "No such file or directory"
perl.xls gets created, but thats it.
I tried this code for degugging:

use Spreadsheet::WriteExcel; use strict; print "Spreadsheet::WriteExcel VERSION $Spreadsheet::WriteExcel::VERSI +ON\n"; unlink("perl.xls"); my $workbook = Spreadsheet::WriteExcel->new("perl.xls") or die "failed to create new workbook: $!"; my $worksheet = $workbook->add_worksheet() or die "failed to create new worksheet: $!"; my $status; eval { $status = $worksheet->write('A1', "Hi Excel!") or die $! }; print "write failed: $@ with status $status\n" if $@;

and get:

Spreadsheet::WriteExcel VERSION 2.10 write failed: No such file or directory at worksheet.pl line 11. with status 0"
Any pointers would be appreciated.... I have also read a fair bit more of the perldoc, but can't find anything.

Cheers Tony

I'm using
v5.8.4 built for MSWin32-x86-multi-thread

Retitled by davido.

Replies are listed 'Best First'.
Re: Spreadsheet::WriteExcel write failure
by rdfield (Priest) on Jan 11, 2005 at 11:39 UTC
    The code works OK if you remove the  or die $! from the line inside the eval - the successful return code appears to be 0 causing the die to be evaluated.

    rdfield

      Hi John and rdfield,
      write returns 0 if successful so of course my code will fail,... if write is successful.
      Dho!
      $! being set to "No such file or directory" is an intersting red herring
      Thanks for the feedback guys
      Cheers
      Tony

        The $! being set like that is often a result of the searching through @INC for a file to be used or required.

        /J\

        A couple of things to note: most modules do not set the variable $! on failure. For example, DBI sets the variable $DBI::errstr for class method errors, and $dbh->errstr for errors concerning a specific database handle. Also, you really have to look at the docs for each module to determine whether a particular method returning undef or false means that the method failed. Generally this will only be true for methods whose return value is specified to have a certain meaning. Spreadsheet::WriteExcel's write method appears not to be one of them. Finally, you have to be careful because unlike $@, $! is not guaranteed to contain a blank string or other false value when no error has occurred, so its value is essentially unpredictable in those circumstances. See perlvar for details.
Re: Spreadsheet::WriteExcel write failure
by jmcnamara (Monsignor) on Jan 11, 2005 at 11:06 UTC

    I never seen or had a report of that error.

    It is may be caused by not having sufficient permissions to create a temp file on your system. Try the following to see where your temp dir is and see if you have write permissions:

    perl -MFile::Spec -le "print File::Spec->tmpdir"
    If that is the problem you can work around it using the set_tempdir() method. See the docs for more information.

    If not let me know.

    Update: I interpreted this to mean that the error message was also occuring with the first piece of code. rdfield++ for spotting the real problem.

    --
    John.

Re: Spreadsheet::WriteExcel write failure
by trammell (Priest) on Jan 11, 2005 at 15:44 UTC
    The following code DWIM:
    #!/usr/bin/perl use warnings; use strict; use Spreadsheet::WriteExcel; my $book = Spreadsheet::WriteExcel->new("perl.xls"); my $sheet = $book->addworksheet(); $sheet->write('A1', 'Hi Excel!');
    Maybe the problem is with addworksheet() (note spelling)?
      No, addworksheet is ok. It's deprecated, but it works. It's a rudiment of older Spreadsheet::WriteExcel versions... In newer versions addworksheet is replaced by add_worksheet.
        Dang, Debian stable is way out of date. :^(

Log In?
Username:
Password:

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

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

    No recent polls found