4 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#! /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 <excel_file> <output_path>
~;
}
exit -1;
}
4 Einträge, 1 Seite |