Splits an excel file of one sheet into separate sheets based on column values. I developed this to deal with a database extract, but it could probably also be used for downloaded excel files.
#!perl -w
use Spreadsheet::BasicRead;
use Spreadsheet::WriteExcel;
($name, $out, $splitter, $sheeter) = @ARGV;
#name = excel file in
#out = excel file out
#splitter = column (0-based) on which to split sheets
#sheeter = data column to use to name sheets
if ($name =~ /\?/){
print "[excel in] [excel out] [split column] [sheet name column]\n";
print "Splits excel sheets into tabs";
die;
}
$spreadin = new Spreadsheet::BasicRead($name) || die "Error: $!";
my $workbook = Spreadsheet::WriteExcel->new($out);
$r=0;
while ($data = $spreadin->getNextRow()){
if ($r == 0){
@head = @{$data};
$header = \@head;
}
$splitcol = $$data[$splitter];
if ($splitcol ne $osplitcol){
$active = $workbook->add_worksheet($$data[6]);
$active->write_row(0, 0, $header);
$r=1;
$osplitcol = $splitcol;
}
$active->write_row($r, 0, $data);
$r++;
}