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

Am trying to read an Excel spreadsheet using Spreadsheet::Read

I've done everything to confirm the file exists, and is a valid file. I've set the file and its directories all to 777. I've downloaded the file from my server to my desktop and verified that it opens up in Excel.

But in the code below, I am falling when I eval the ReadData method.

Where I'm stuck is that other that failing on the eval, I don't know if or how to get further data on why Spreadsheet::Read fails with trying to open my spreadsheet.

If anyone has any experience using this module, I'd appreciate any help.

Thank you.

$filename = "R202406181844029040.xlsx" if ($testMode); my ($ext) = "$upload_dir/$filename" =~ /(\.[^.]+)$/; $ext =~ s/\.//g; $ext =~ s/^\s+|\s+$//g; my $book; my $upFilename = "$upload_dir/$filename"; $logger->debug("entering eval with $upFilename "); if (-e $upFilename) { $logger->debug("file exists"); } else { $logger->debug("file DOES NOT exists"); } eval { $book = ReadData ("$upFilename"); 1; } or do { ...handle error here };
  • Comment on Failing with ReadData from Spreadsheet::Read and need to find a way to debug
  • Download Code

Replies are listed 'Best First'.
Re: Failing with ReadData from Spreadsheet::Read and need to find a way to debug
by stevieb (Canon) on Jun 19, 2024 at 00:06 UTC

    What directory is the file in? What directory is the script in? Have you tried putting the script and file in the same directory and running it with the filename only? Most importantly, what is the error message?

    When you execute your error handler, you should be printing out $@ to see what errors are produced in the eval.

Re: Failing with ReadData from Spreadsheet::Read and need to find a way to debug
by The_Dj (Scribe) on Jun 19, 2024 at 00:53 UTC
    Yes, the error from ReadData should hold some clues.

    I've had a case where certain strings were confusing an excel parser, so also check if this works with a super simple spreadsheet.
    (Something with just a single word in a single cell to start.)

    Luck!

      This reply is for all replies to my OP:

      This is sort of my fault, in that I program on the other side of linux machines, so I only have a basic knowledge of perl, and even though I've used $@ before, that thinking doesn't come automatically for that.

      So now that you all reminded me of $@, the error makes sense, "No parser for XLSX found."

      Am trying hard to install all the parsers, with CPAN. but I keep getting errors that I am missing a prerequisite, and eventually I get bad tests when installing modules from CPAN.

      i.e.
      Test Summary Report ------------------- t/prng_rc4.t (Wstat: 132 Tests: 0 Failed: 0) Non-zero wait status: 132 Parse errors: Bad plan. You planned 19 tests but ran 0. Files=137, Tests=18549, 49 wallclock secs ( 4.46 usr 0.76 sys + 36.90 cusr 3.93 csys = 46.05 CPU) Result: FAIL Failed 1/137 test programs. 0/18549 subtests failed. make: *** Makefile:1780: test_dynamic Error 255 MIK/CryptX-0.080.tar.gz make test -- NOT OK //hint// to see the cpan-testers results for installing this module, try: reports MIK/CryptX-0.080.tar.gz

      I'm guessing this is a question for another forum, like Stack Overflow, but isn't there a simple way to instal a perl module, and any dependents it requires?

      Thanks for the original replies, at least I have a clue now

        I'm guessing this is a question for another forum, like Stack Overflow

        Why? Because we here at Perlmonks led you to look at the error in $@, and now we're not qualified enough? Please note that the most intelligent Perl Hackers are found here on Perlmonks ;)

        but isn't there a simple way to instal a perl module, and any dependents it requires?

        Yes, there is. My fellow Monks have shared their thoughts on that. (Hint cpanm).

        The doc for Spreadsheet::Read says "For Microsoft Excel this module uses Spreadsheet::ParseExcel". I would install that module.
Re: Failing with ReadData from Spreadsheet::Read and need to find a way to debug
by swl (Prior) on Jun 19, 2024 at 00:08 UTC

    What is the error from the ReadData call?