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++; }

In reply to Xtabber by SamCG

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.