ParseExcel::Simple not working?
am 22.09.2005 00:32:20 von rickcasey
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 () {
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
...., line ...
Any help appreciated,
rixter
Re: ParseExcel::Simple not working?
am 22.09.2005 02:28:01 von Jim Gibson
In article <1127341940.525023.216750@g43g2000cwa.googlegroups.com>,
rixter wrote:
> 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 () {
> 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
> ..., line ...
>
> Any help appreciated,
> rixter
>