summaryrefslogtreecommitdiffstats
path: root/bin/combine_csv
blob: f17db89b9496d0215aaf4ecf3ab01341bb8c25d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env perl
use strict;
use warnings;

use Path::Class;
use Spreadsheet::WriteExcel;
use Text::CSV;

my @csv_files = map { file($_) } @ARGV;

my $ss = Spreadsheet::WriteExcel->new('combined.xls');

for my $csv_file (@csv_files) {
    my $name = $csv_file->stringify;
    $name =~ s/\.csv$//;
    my $ws = $ss->add_worksheet($name);

    my $parser = Text::CSV->new;
    my $fh = $csv_file->openr;
    my $row_num = 1;
    while (my $row = $parser->getline($fh)) {
        for my $col_num (0..$#$row) {
            $ws->write($row_num, $col_num, $row->[$col_num]);
        }
        $row_num++;
    }
}