From: Ben Ostrowsky Date: Tue, 29 Dec 2009 15:40:01 +0000 (+0000) Subject: A tool I found online X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=c921e409f5ff2555ef1ae33f6c9cc14c5c33f0ae A tool I found online --- diff --git a/xls2tab b/xls2tab new file mode 100755 index 0000000..8ddc19f --- /dev/null +++ b/xls2tab @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +#~ Converter Script for XLS to TSV. Handles Multiple Tabs into separate files. +#~ (c)2004 Anima Legato +#~ +#~ This code is redistributable and modifiable under the same terms as Perl +#~ itself. + +use strict; +use warnings; + +use Spreadsheet::ParseExcel::Simple; +use File::Spec; + +for (@ARGV) { + for (glob $_) { + next unless m/\.xls$/i; + next unless -r $_; + dump_books($_); + } +} + +sub dump_books { + my ($vol, $path, $file) = File::Spec->splitpath(shift); + my $eBook = Spreadsheet::ParseExcel::Simple->read(File::Spec->catpath($vol,$path,$file)); + unless (defined $eBook) { + warn "Can't open Spreadsheet in file $file (@".File::Spec->catpath($vol,$path,$file)."\n"; + return undef; + } + + my @sheet = $eBook->sheets; + for (0..@sheet-1) { + next unless $sheet[$_]->has_data(); + my $sfn = $file; + $sfn =~ s?\.xls$??i; + $sfn.= ((@sheet > 1) ? sprintf(".%02i",$_) : "").'.tab'; + open TAB, '>', $sfn or do { + warn "Unable to write to $sfn"; + next; + }; + + while ($sheet[$_]->has_data) { + my @row = $sheet[$_]->next_row; + print TAB join("\t",@row)."\n"; + } + } +} ##--dump_books--##