Run from command line. Simply parses an excel file and saves it as a tab-delimited file.

#!/usr/local/bin/perl ###################### # Author: Alan Hamlett # Date: 03/18/2009 ###################### use strict; use Spreadsheet::ParseExcel; my $inputFile = shift; my $outputFile = shift; if(!-e $inputFile || !$outputFile) { print qq~ Usage: excelToTabDelim inputFile outputFile Parses an excel input file into a tab delimited out file ~; exit 1; } if(open(OUT, "> $outputFile")) { my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($inputFile +); foreach my $worksheet (@{$workbook->{Worksheet}}) { # looping thro +ugh worksheets for(my $row = $worksheet->{MinRow}; defined $worksheet->{MaxRo +w} && $row <= $worksheet->{MaxRow}; $row++) { # loop through rows my @line; for(my $column = $worksheet->{MinCol}; defined $worksheet- +>{MaxCol} && $column <= $worksheet->{MaxCol}; $column++) { # loop thr +ough columns my $value = $worksheet->{Cells}[$row][$column] ? $work +sheet->{Cells}[$row][$column]->Value : ""; $value =~ s/^\s+//; $value =~ s/\s+$//; $value =~ s/[\r\n]+//g; $value = " " if $value ne "0" && !$value; push(@line, $value); } $" = "\t"; print OUT "@line\n"; } } close(OUT); } else { print "Error: Could not write to output file '$outputFile'\n"; }

In reply to Excel To Tab Delimited using Spreadsheet::ParseExcel by upallnight

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.