#! /usr/bin/perl use strict; use warnings; use lib qw(./cpan/perllib); use Spreadsheet::ParseExcel; my $file = (-f $ARGV[0]) ? $ARGV[0] : print_error($ARGV[0]."is not a file"); my $home = -d $ARGV[1] ? $ARGV[1] : print_error($ARGV[1]."is not a directory"); print_error('wrong parameters','use') unless($file && $home); my $xls = Spreadsheet::ParseExcel::Workbook->Parse($file) or print_error($!); foreach my $workbook(@{$xls->{Worksheet}}){ my $csv = $home.'/'.$workbook.'.csv'; print "CSV: $csv\n"; open(W_CSV,">$csv") or print_error($csv." ".$!); for(my $row = $workbook->{MinRow}; defined $workbook->{MaxRow} && $row <= $workbook->{MaxRow}; $row++){ my @values = (); for(my $col = $workbook->{MinCol}; defined $workbook->{MaxCol} && $col <= $workbook->{MaxCol}; $col++){ my $cell = $workbook->{Cells}[$row][$col]; my $val = $cell ? $cell->Value : ''; push(@values, $val); } print W_CSV join(';',@values),"\n"; } close W_CSV; } sub print_error{ print STDERR "Error: ",shift,"\n"; if(shift eq 'use'){ print qq~ Usage: $0 ~; } exit -1; }