Webspeeder
Programmer
Hey all.
I have some code that I'm having an issue with and it is getting extremely frustrating. I started with perl code that I had copied and modified as needed and then a fellow tried to help me and although he cleaned the code up, it still doesn't work. Since I'm not a native Perl programmer, I am having difficulty figuring this out. From all the examples I've seen, the code appears to be correct.
The error I'm getting concerns the get_cell line. Here is the error.
Can't locate object method "get_cell" via package "Spreadsheet:
arseExcel::Worksheet" at xls2csv.pl line 84.
Any help would be greatly appreciated.
I don't see how to simply attach code, so here is the code.
/*** CODE BEGIN ****/
#!/usr/bin/perl -w
##################################################################################
# xls2csv.pl - parses an excel spreadsheet and writes it back out as a csv file. #
##################################################################################
use strict;
use warnings;
# Ensure All Arguements Provided
################################
if ( !(defined $ARGV[0]) ) {
print "Usage: ", $0 , " Excel_File\n";
exit;
}
if ( !(defined $ARGV[1]) ) {
print "Usage: ", $1 , " Starting Line Number\n";
exit;
}
# Package Declarations
######################
use Time::localtime;
use File::Copy;
use Spreadsheet:
arseExcel;
# Initialize Objects
####################
my $oExcel = new Spreadsheet:
arseExcel;
my $tm = localtime;
# Datafile path $ARGV[2] should be either blank or './'
#######################################################
my $datapath;
if ( !(defined $ARGV[2]) ) { $datapath = './' } else { $datapath = $ARGV[2] };
# Parse(Read) in the spreadsheet
################################
my $oBook = $oExcel->Parse($datapath.$ARGV[0]);
# Split filename to change extension later
##########################################
my @filesplit = split /\./,$ARGV[0];
# Assume Data stored in 1st Sheet
#################################
my $oWkS = $oBook->{Worksheet}[0];
# Check to see if the worksheet has any data
############################################
if ( defined $oWkS->{MaxRow} ) {
# Gather Worksheet Dimensions
#############################
my %DIMENSIONS;
$DIMENSIONS{minRow} = $oWkS->{MinRow};
$DIMENSIONS{maxRow} = $oWkS->{MaxRow};
$DIMENSIONS{minCol} = $oWkS->{MinCol};
$DIMENSIONS{maxCol} = $oWkS->{MaxCol};
# Define New Output Filename
############################
my $filename = $datapath . $filesplit[0] . ".csv";
# Open Filehandle ready for output
##################################
open(OUT, ">" . $filename) || die "Could not open ".$filename."\n";
# Loop through each Row
#######################
for ( my $row = $DIMENSIONS{minRow}; $row <= $DIMENSIONS{maxRow}; $row++ ) {
# Skip row if start row is higher
#################################
if ( $row <= $ARGV[1] ) {
next;
}
# Loop through each Column
##########################
for ( my $column = $DIMENSIONS{minCol}; $column <= $DIMENSIONS{maxCol}; $column++ ) {
# Gather Data from Cell
#######################
my $cell = $oWkS->get_cell($row, $column);
if ( $cell && $cell->unformatted() ) {
# Output data to CSV file
#########################
print OUT $cell->unformatted();
# Seperate Cell with Delimter if not end column
###############################################
if ( $column < $DIMENSIONS{maxCol} ) {
print OUT "|";
}
# New Line if end Column
########################
else {
print OUT "\n";
}
}
}
}
# Close File Handle
###################
close(OUT);
}
exit;
/*** CODE END ****/
I have some code that I'm having an issue with and it is getting extremely frustrating. I started with perl code that I had copied and modified as needed and then a fellow tried to help me and although he cleaned the code up, it still doesn't work. Since I'm not a native Perl programmer, I am having difficulty figuring this out. From all the examples I've seen, the code appears to be correct.
The error I'm getting concerns the get_cell line. Here is the error.
Can't locate object method "get_cell" via package "Spreadsheet:
Any help would be greatly appreciated.
I don't see how to simply attach code, so here is the code.
/*** CODE BEGIN ****/
#!/usr/bin/perl -w
##################################################################################
# xls2csv.pl - parses an excel spreadsheet and writes it back out as a csv file. #
##################################################################################
use strict;
use warnings;
# Ensure All Arguements Provided
################################
if ( !(defined $ARGV[0]) ) {
print "Usage: ", $0 , " Excel_File\n";
exit;
}
if ( !(defined $ARGV[1]) ) {
print "Usage: ", $1 , " Starting Line Number\n";
exit;
}
# Package Declarations
######################
use Time::localtime;
use File::Copy;
use Spreadsheet:
# Initialize Objects
####################
my $oExcel = new Spreadsheet:
my $tm = localtime;
# Datafile path $ARGV[2] should be either blank or './'
#######################################################
my $datapath;
if ( !(defined $ARGV[2]) ) { $datapath = './' } else { $datapath = $ARGV[2] };
# Parse(Read) in the spreadsheet
################################
my $oBook = $oExcel->Parse($datapath.$ARGV[0]);
# Split filename to change extension later
##########################################
my @filesplit = split /\./,$ARGV[0];
# Assume Data stored in 1st Sheet
#################################
my $oWkS = $oBook->{Worksheet}[0];
# Check to see if the worksheet has any data
############################################
if ( defined $oWkS->{MaxRow} ) {
# Gather Worksheet Dimensions
#############################
my %DIMENSIONS;
$DIMENSIONS{minRow} = $oWkS->{MinRow};
$DIMENSIONS{maxRow} = $oWkS->{MaxRow};
$DIMENSIONS{minCol} = $oWkS->{MinCol};
$DIMENSIONS{maxCol} = $oWkS->{MaxCol};
# Define New Output Filename
############################
my $filename = $datapath . $filesplit[0] . ".csv";
# Open Filehandle ready for output
##################################
open(OUT, ">" . $filename) || die "Could not open ".$filename."\n";
# Loop through each Row
#######################
for ( my $row = $DIMENSIONS{minRow}; $row <= $DIMENSIONS{maxRow}; $row++ ) {
# Skip row if start row is higher
#################################
if ( $row <= $ARGV[1] ) {
next;
}
# Loop through each Column
##########################
for ( my $column = $DIMENSIONS{minCol}; $column <= $DIMENSIONS{maxCol}; $column++ ) {
# Gather Data from Cell
#######################
my $cell = $oWkS->get_cell($row, $column);
if ( $cell && $cell->unformatted() ) {
# Output data to CSV file
#########################
print OUT $cell->unformatted();
# Seperate Cell with Delimter if not end column
###############################################
if ( $column < $DIMENSIONS{maxCol} ) {
print OUT "|";
}
# New Line if end Column
########################
else {
print OUT "\n";
}
}
}
}
# Close File Handle
###################
close(OUT);
}
exit;
/*** CODE END ****/