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

I'm trying to use Spreadsheet::ParseExcel to read an excel file. But i'm getting the following error when the program tries to parse the source file. "Could not open source Excel file"

Piece of source code:
my $source_excel = new Spreadsheet::ParseExcel; my $source_book = $source_excel->Parse($sourcename) or die "Could not open source Excel file $sourcename: $!";
Suggestions?

Edit: Added <code> tags. Fixed minor typo. larsen


updated by boo_radley : title change

Replies are listed 'Best First'.
Re: SpreadSheet::ParseExcel
by gt8073a (Hermit) on May 25, 2002 at 11:40 UTC

    "Could not open source Excel file"

    did you define $sourcename? does it point to the correct file? do you have proper permissions?

    It is difficult to say what is wrong because you only pasted part( the less useful part at that ) of the error message.

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com

      Hi! I hv defined $sourcename; i do hv the required permissions properly set up. The source file is taken from the command line argument. I guess if it doesn't point to correct file, the error would be something different. This program used to work earlier and now it gives this error for any excel file gievn as input. The complete error message i get whenever i tried to run this program is : "Could not open source Excel file myglus.xls: at Excel.pl line 21."
Re: File open errors using SpreadSheet::ParseExcel (was : SpreadSheet::ParseExcel)
by gt8073a (Hermit) on May 28, 2002 at 06:20 UTC

    I created an empty file, test.xls, and ran the following script. I died with:

    Can not parse 'test.xls': at excel.pl line 11.

    However, when I tried to open a real .xls file, everything went smoothly.

    #!/usr/bin/perl -w use strict; use Spreadsheet::ParseExcel; my $file; $file = 'test.xls'; my $oExcel = new Spreadsheet::ParseExcel; my $oBook = $oExcel->Parse( $file ) or die "Can not parse '$file': $!"; print $oBook, "\n"; exit(0);

    It appears you are either opening $sourcename correctly, or you are not reaching the open call. You can use pieces of the code from the module and write yourself another script which walks the _subGetContent subroutine( I hope that is the correct sub, I did not do it myself.. ). Or, try using Win32::OLE( here is a link to an example on IBM's site ).

    Sorry, I can not be of any more help than that.

    Will perl for money
    JJ Knitis
    (901) 756-7693
    gt8073a@industrialmusic.com