NAME
authorGalen Charlton <gmc@esilibrary.com>
Tue, 13 Apr 2010 00:19:06 +0000 (00:19 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 13 Apr 2010 00:19:06 +0000 (00:19 +0000)
       xlsx2tab

SUMMARY
       Quick-and-dirty filter lifted from the Spreadsheet::XSLX POD to convert the first sheet of an Excel .xlsx file to TSV

USAGE
       xlsx2tab foo.xlsx > foo.tsv

xlsx2tab [new file with mode: 0755]

diff --git a/xlsx2tab b/xlsx2tab
new file mode 100755 (executable)
index 0000000..8467ecd
--- /dev/null
+++ b/xlsx2tab
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+=head1 NAME
+
+xlsx2tab
+
+=head1 SUMMARY
+
+Quick-and-dirty filter lifted from the Spreadsheet::XSLX POD
+to convert the first sheet of an Excel .xlsx file to TSV
+
+=head1 USAGE
+
+xlsx2tab foo.xlsx > foo.tsv
+
+=cut
+
+use Spreadsheet::XLSX;
+use Text::Iconv;
+my $converter = Text::Iconv->new ("utf-8", "windows-1251");
+my $excel = Spreadsheet::XLSX->new ($ARGV[0], $converter);
+foreach my $sheet (@{$excel->{Worksheet}}) {
+    $sheet->{MaxRow} ||= $sheet->{MinRow};
+    foreach my $row ($sheet->{MinRow} .. $sheet->{MaxRow}) {
+        print join("\t", map { $_->unformatted() } @{ $sheet->{Cells}[$row] }), "\n";
+    }
+    last; # only look at the first worksheet for now
+}