|
0
|
1 #!/usr/bin/perl
|
|
|
2
|
|
|
3 #~ Converter Script for XLS to TSV. Handles Multiple Tabs into separate files.
|
|
|
4 #~ (c)2004 Anima Legato <l3gatosan@gmail.com>
|
|
|
5 #~
|
|
|
6 #~ This code is redistributable and modifiable under the same terms as Perl
|
|
|
7 #~ itself.
|
|
|
8
|
|
|
9 use strict;
|
|
|
10 use warnings;
|
|
|
11
|
|
|
12 use Spreadsheet::ParseExcel::Simple;
|
|
|
13
|
|
|
14 for (@ARGV) {
|
|
|
15 for (glob $_) {
|
|
|
16 next unless m/\.xls$/i;
|
|
|
17 next unless -r $_;
|
|
|
18 dump_books($_);
|
|
|
19 }
|
|
|
20 }
|
|
|
21
|
|
|
22 sub dump_books {
|
|
|
23 my $file = shift;
|
|
|
24 my $eBook = Spreadsheet::ParseExcel::Simple->read($file);
|
|
|
25 unless (defined $eBook) {
|
|
|
26 warn "Can't open Spreadsheet in file $file (@".$file."\n";
|
|
|
27 return undef;
|
|
|
28 }
|
|
|
29 my @sheet = $eBook->sheets;
|
|
|
30 for (0..0) {
|
|
|
31 next unless $sheet[$_]->has_data();
|
|
|
32 #my $sfn = $file;
|
|
|
33 #$sfn =~ s?\.xls$??i;
|
|
|
34 #$sfn.= ((@sheet > 1) ? sprintf(".%02i",$_) : "").'.tsv';
|
|
|
35 #open TAB, '>', $sfn or do {
|
|
|
36 # warn "Unable to write to $sfn";
|
|
|
37 # next;
|
|
|
38 #};
|
|
|
39
|
|
|
40 while ($sheet[$_]->has_data) {
|
|
|
41 my @row = $sheet[$_]->next_row;
|
|
|
42 print join("\t",@row)."\n"; # print TAB ...
|
|
|
43 }
|
|
|
44 }
|
|
|
45 } ##--dump_books--##
|