Click here to get back home

ParseExcel::Simple not working?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
ParseExcel::Simple not working? rixter 09-21-2005
Posted by rixter on September 21, 2005, 3:32 pm
Please log in for more thread options


Apparently many people find ParseExcel and ParseExcel::Simple very
useful, but I have not been able to get it working. After reading
extensively in the perl newsgroups and testing all I can, am hoping
someone else might help me spot what's amiss. Having the ability to
read spreadsheets directly from Perl would have great value where I
work, so I'm hoping this will happen!

Here's the (relevant) code:

use Getopt::Std;
use IBG::StudyIDparser;
use FileHandle;
use DBI;
use OLE::Storage_Lite;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::Simple;

$rootdir = '/mydir/';
$filelist = "mySSlist.txt";
open (FILELIST,"< $filelist") or die "Could not open input file:
$filelist";
while (<FILELIST>) {
        chomp($_);
        if (! -f $_) {
                die "File $_ not found!\n";
        }
        $ss_file = $rootdir.$_;
        print "Processing $_\n";
        # For now:
        # Just print out rows as a test....
        my $xls = Spreadsheet::ParseExcel::Simple->read('$ss_file');
        my $sheet = ($xls->sheets)[0]; # all the spreadsheets have just one
worksheet
        while ($sheet->has_data) {
                my @data = $sheet->next_row;
                print @data;
        }
}

Here's the error message:
Can't call method "sheets" on an undefined value at impcore_ss.pl line
...., <FILELIST> line ...

Any help appreciated,
rixter



Posted by Jim Gibson on September 21, 2005, 5:28 pm
Please log in for more thread options



> Apparently many people find ParseExcel and ParseExcel::Simple very
> useful, but I have not been able to get it working. After reading
> extensively in the perl newsgroups and testing all I can, am hoping
> someone else might help me spot what's amiss. Having the ability to
> read spreadsheets directly from Perl would have great value where I
> work, so I'm hoping this will happen!
>
> Here's the (relevant) code:
>
> use Getopt::Std;
> use IBG::StudyIDparser;
> use FileHandle;
> use DBI;
> use OLE::Storage_Lite;
> use Spreadsheet::ParseExcel;
> use Spreadsheet::ParseExcel::Simple;
>
> $rootdir = '/mydir/';
> $filelist = "mySSlist.txt";
> open (FILELIST,"< $filelist") or die "Could not open input file:
> $filelist";

Have you tried getting a program to read a single spreadsheet before
getting it to read a list of spreadsheets? Walk before you run!

> while (<FILELIST>) {
> chomp($_);
> if (! -f $_) {
> die "File $_ not found!\n";
> }
> $ss_file = $rootdir.$_;
> print "Processing $_\n";

You test $_ for existence and print $_, but you are processing
"/mydir/$_". Try checking the string in $ss_file for existence. If
/mydir/ is not your default directory, that is your first problem.

> # For now:
> # Just print out rows as a test....
> my $xls = Spreadsheet::ParseExcel::Simple->read('$ss_file');

You do not test $xls before trying to use it. The error message you get
tells you that it is undefined. The documentation says that the read
method returns undefined if it "cannot read the book" (workbook). You
are trying to read a spreadsheet document called (literally)
'$ss_file'. Remove the single quotes (double quotes might work but are
unnecessary):

my $xls = Spreadsheet::ParseExcel::Simple->read($ss_file);
die("Can't read $ss_file") unless defined $xls;

> my $sheet = ($xls->sheets)[0]; # all the spreadsheets have just one
> worksheet
> while ($sheet->has_data) {
> my @data = $sheet->next_row;
> print @data;
> }
> }
>
> Here's the error message:
> Can't call method "sheets" on an undefined value at impcore_ss.pl line
> ..., <FILELIST> line ...
>
> Any help appreciated,
> rixter
>


Similar ThreadsPosted
Spreadsheet::ParseExcel November 16, 2006, 6:55 am
Spreadsheet::ParseExcel error on Perl 5.8.0 November 7, 2005, 6:02 am
FmtDefault-Warning in Spreadsheet-ParseExcel December 20, 2005, 10:50 am
Spreadsheet::ParseExcel::SaveParser changes formula text to value August 25, 2004, 9:52 am
Spreadsheet::ParseExcel : read cell-notes May 27, 2005, 11:54 am
Spreadsheet-ParseExcel: Parsing various MS Excel file versions / grabing checkbox values? September 17, 2004, 3:11 am
GD not working September 13, 2004, 2:52 pm
Anyone working on ALSA ? October 5, 2007, 2:02 am
CPAN configuration help get working October 12, 2004, 6:32 pm
Net::Telnet not working with perl 5.8.5 November 15, 2005, 2:48 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap