summaryrefslogtreecommitdiffstats
path: root/bin/explode_csv
diff options
context:
space:
mode:
Diffstat (limited to 'bin/explode_csv')
-rwxr-xr-xbin/explode_csv46
1 files changed, 0 insertions, 46 deletions
diff --git a/bin/explode_csv b/bin/explode_csv
deleted file mode 100755
index 8f50ebc..0000000
--- a/bin/explode_csv
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/env perl
-use strict;
-use warnings;
-
-use Module::Runtime qw< require_module >;
-use Text::CSV;
-
-my $filename = $ARGV[0];
-my $parser_class = $filename =~ /\.xlsx$/
- ? "Spreadsheet::ParseXLSX"
- : "Spreadsheet::ParseExcel";
-
-require_module($parser_class);
-
-my $parser = $parser_class->new;
-my $wb = $parser->parse($filename) || die $parser->error;
-
-(my $dir = $filename) =~ s/\.[^.]*$//;
-mkdir $dir;
-chdir $dir;
-
-for my $ws ($wb->worksheets) {
- my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
- my $filename = $ws->get_name . '.csv';
- open my $fh, '>:encoding(UTF-8)', $filename
- or die "Couldn't open $filename: $!";
-
- my ($rmin, $rmax) = $ws->row_range;
- my ($cmin, $cmax) = $ws->col_range;
-
- for my $row (0..$rmin - 1) {
- $csv->print($fh, [ ('') x ($cmax + 1) ]);
- }
-
- for my $row ($rmin..$rmax) {
- my @row = (('') x $cmin);
- for my $col ($cmin..$cmax) {
- my $cell = $ws->get_cell($row, $col);
- push @row, $cell ? $cell->value : '';
- }
- $csv->print($fh, \@row);
- }
-
- close $fh
- or die "Couldn't close $filename: $!";
-}