view bin/xls2tsv.pl @ 0:2aa53823fb21

new repo
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Sat, 06 Jun 2026 10:19:04 +0100
parents
children
line wrap: on
line source

#!/usr/bin/perl

#~ Converter Script for XLS to TSV.  Handles Multiple Tabs into separate files.
#~ (c)2004 Anima Legato <l3gatosan@gmail.com>
#~
#~ This code is redistributable and modifiable under the same terms as Perl
#~ itself.

use strict;
use warnings;

use Spreadsheet::ParseExcel::Simple;

for (@ARGV) {
    for (glob $_) {
        next unless m/\.xls$/i;
        next unless -r $_;
        dump_books($_);
    }
}

sub dump_books {
    my $file = shift;
    my $eBook = Spreadsheet::ParseExcel::Simple->read($file);
    unless (defined $eBook) {
        warn "Can't open Spreadsheet in file $file (@".$file."\n";
        return undef;
    }
    my @sheet = $eBook->sheets;
    for (0..0) {
        next unless $sheet[$_]->has_data();
        #my $sfn = $file;
        #$sfn =~ s?\.xls$??i;
        #$sfn.= ((@sheet > 1) ? sprintf(".%02i",$_) : "").'.tsv';
        #open TAB, '>', $sfn or do {
         #   warn "Unable to write to $sfn";
          #  next;
        #};
        
        while ($sheet[$_]->has_data) { 
            my @row = $sheet[$_]->next_row;
            print join("\t",@row)."\n"; # print TAB ...
        }
    }
} ##--dump_books--##