CSV
CSV
/usr/bin/perl
use strict;
use warnings;
# Declarations
#===========================================================
use Spreadsheet::ParseExcel;
# Program proper
#===========================================================
my $file_name = shift || usage();
parse_excel($file_name);
exit 0;
# Subroutines
#===========================================================
sub parse_excel {
my %arg = ( record_sep => "\n",
field_sep => "\t",
xls
=> undef );
if ( @_ == 1 ) {
$arg{xls} = shift;
} elsif ( not @_ % 2 ) {
%arg = ( %arg, @_ );
}
-e $arg{xls} or
die "Must provide valid XLS file! $arg{xls}, $!\n";
# create a ParseExcel object
my $excel_obj = Spreadsheet::ParseExcel->new();
my $workbook = $excel_obj->Parse($arg{xls});
# make sure we're in business
die "Workbook did not return worksheets!\n"
unless ref $workbook->{Worksheet} eq 'ARRAY';
# we need to get each worksheet from the workbook in turn
for my $worksheet ( @{$workbook->{Worksheet}} ) {
# {Cells}[row][col]
# empty worksheets have undef for MaxCol and MaxRow
my $last_col = $worksheet->{MaxCol} || 0;
my $last_row = $worksheet->{MaxRow} || 0;
for my $row ( 0 .. $last_row ) {
for my $col ( 0 .. $last_col ) {
my $cell = $worksheet->{Cells}[$row][$col];
print ref $cell ?
$cell->Value : '';