S
Shawn
Hi,
We are using the below script to convert a file into excel format. The
problem is that my file contains ssn in which they can start with zero.
Well, when it gets converted to excel it drops the leading zero. I need
that leading zero and am not sure how to modify this script to keep the
zero.
Any asistance would be greatly appreciated!
Shawn
--
#!/opt/bin/perl5.6 -w
############################################################################
###
# Example of how to use the WriteExcel module
# Program to convert a text [delim] separated value file into an Excel file.
# Usage: txt2xls.pl file.txt newfile.xls
use Getopt::Long;
use Spreadsheet::WriteExcel::Big;
GetOptions ("d=s" => \$delim);
$delim = "|" if !defined($delim);
$delim =~ s/\|/\\|/g;
# Check for valid number of arguments
if (($#ARGV < 1) || ($#ARGV > 2)) {
die("Usage: txt2xls file.txt newfile.xls\n");
};
# Open the Comma Seperated Variable file
open (TXTFILE, $ARGV[0]) or die "$ARGV[0]: $!";
# Create a new Excel workbook
my $workbook = Spreadsheet::WriteExcel::Big->new($ARGV[1]);
my $worksheet = $workbook->add_worksheet();
# Row and column are zero indexed
my $row = 0;
while (<TXTFILE>) {
chomp;
@cols = split(/\s*${delim}\s*/,$_);
$col = 0;
foreach my $token (@cols) {
$worksheet->write($row, $col, $token);
$col++;
}
$row++;
}
We are using the below script to convert a file into excel format. The
problem is that my file contains ssn in which they can start with zero.
Well, when it gets converted to excel it drops the leading zero. I need
that leading zero and am not sure how to modify this script to keep the
zero.
Any asistance would be greatly appreciated!
Shawn
--
#!/opt/bin/perl5.6 -w
############################################################################
###
# Example of how to use the WriteExcel module
# Program to convert a text [delim] separated value file into an Excel file.
# Usage: txt2xls.pl file.txt newfile.xls
use Getopt::Long;
use Spreadsheet::WriteExcel::Big;
GetOptions ("d=s" => \$delim);
$delim = "|" if !defined($delim);
$delim =~ s/\|/\\|/g;
# Check for valid number of arguments
if (($#ARGV < 1) || ($#ARGV > 2)) {
die("Usage: txt2xls file.txt newfile.xls\n");
};
# Open the Comma Seperated Variable file
open (TXTFILE, $ARGV[0]) or die "$ARGV[0]: $!";
# Create a new Excel workbook
my $workbook = Spreadsheet::WriteExcel::Big->new($ARGV[1]);
my $worksheet = $workbook->add_worksheet();
# Row and column are zero indexed
my $row = 0;
while (<TXTFILE>) {
chomp;
@cols = split(/\s*${delim}\s*/,$_);
$col = 0;
foreach my $token (@cols) {
$worksheet->write($row, $col, $token);
$col++;
}
$row++;
}