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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |