Skip to content

Commit

Permalink
such a repetitive task...
Browse files Browse the repository at this point in the history
  • Loading branch information
gugod committed May 2, 2015
1 parent bacde3d commit 293794c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xls2csv
@@ -0,0 +1,37 @@
#!/usr/bin/env perl

use strict;
use warnings;


use Text::CSV;
use Spreadsheet::ParseExcel;

my $csv = Text::CSV->new({binary=>1});

my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse( $ARGV[0] );

if ( !defined $workbook ) {
die $parser->error(), ".\n";
}

for my $worksheet ( $workbook->worksheets() ) {

my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();

for my $row ( $row_min .. $row_max ) {
my @line;

for my $col ( $col_min .. $col_max ) {

my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
push @line, $cell->unformatted;
}

$csv->combine(@line);
print $csv->string . "\n";
}
}

0 comments on commit 293794c

Please sign in to comment.