| Category: | Utility Scripts |
| Author/Contact Info | Devin Austin devin.austin@timorperfectus.com |
| Description: | Simple conversion script for Excel to a pipe ("|") delimited text file. Takes two arguments, the filename (can be relative) and the directory to save the text file to. |
#!perl -w
use warnings;
use strict;
## Author: Devin Austin
## Excel to Text script
## very simple script...
## enter file name and get going!
## Usage: convert.pl <excel file> <directory to save text file to>
## Thanks to GrandFather for pretty much re-factoring my original code
## into this version.
## mostly straight out of the docs...
use Spreadsheet::ParseExcel;
my $oExcel = new Spreadsheet::ParseExcel;
my $dir = $ARGV[1];
chomp $dir;
unless (-d $dir) {
print "Can't find directory $dir";
exit;
}
my $filename = "$dir/$ARGV[0]";
chomp $filename;
unless (-e $filename) {
print "Can't find file $filename";
exit ;
}
my $fullfilename = "$filename.txt";
## start work
print "Converting...";
#1.1 Normal Excel97
open E2T, ">", $fullfilename or die $!;
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($filename);
my($iR, $iC, $oWkS, $oWkC);
foreach my $oWkS (@{$oBook->{Worksheet}}) {
print "--------- SHEET:", $oWkS->{Name}, "\n";
print E2T $oWkS->{Name}, "|";
next unless defined $oWkS->{MinRow} and defined $oWkS->{MaxRow};
for my $iR ($oWkS->{MinRow} .. $oWkS->{MaxRow}) {
for my $iC ($oWkS->{MinCol} .. $oWkS->{MaxCol}) {
$oWkC = $oWkS->{Cells}[$iR][$iC];
next if ! defined $oWkC;
print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);
print E2T $oWkC->Value, "|";
}
}
print E2T "\n";
}
close E2T;
print "Finished!";
exit;
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Excel2Text
by mikeB (Friar) on Dec 19, 2006 at 15:59 UTC | |
by stonecolddevin (Parson) on Dec 19, 2006 at 21:35 UTC | |
by GrandFather (Saint) on Dec 19, 2006 at 21:41 UTC | |
by stonecolddevin (Parson) on Dec 19, 2006 at 22:01 UTC | |
|
Re: Excel2Text
by Tux (Canon) on Jan 02, 2007 at 14:55 UTC |