Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

PERL Conversion of XLS to CSV replaces decimals with 'GENERAL'

Avatar of Webspeeder
WebspeederFlag for United States of America asked on
PerlMicrosoft Excel
16 Comments1 Solution1657 ViewsLast Modified:
Hey all.

I have some perl code (below) that, when it converts a decimal field from the XLS file to the CSV file, it converts the decimal to the word "general".

Any ideas why this happens? I added decimal values to a string field and it came through fine so it must have something to do with the way PERL handles decimals?
#!/usr/bin/perl
# xls2csv.pl - parses an excel spreadsheet and writes it back out as a csv file.
# receives 2 arguement - 
#   $ARGV[0] - Excel filename
#   $ARGV[1] - New Filename
# example: xls2csv.pl setex.xls

use strict; 
# make sure all arguements were provided
if(!(defined $ARGV[0])) { 
    print "Usage: ", $0 , " Excel_File\n"; 
    exit; 
} 

if(!(defined $ARGV[1])) { 
    print "Usage: ", $1 , " Starting Line Number\n"; 
    exit; 
} 

#if(!(defined $ARGV[2])) { 
#    print "Usage: ", $2 , " Need to define input directory\n"; 
#    exit; 
#} 

# Package declarations
use Time::localtime;
use File::Copy;
use Spreadsheet::ParseExcel; 

# Initialize Objects #####################################################
my $oExcel = new Spreadsheet::ParseExcel; 
my $tm = localtime;
my $xcount;
my $ycount;
my $oWkS;
my $oWkC;
my $filename;

# datafile path $ARGV[2] should be either blank or ./, depending on how this script is ran
# If it is ran from within a program, send blank. If it is ran from command line in current directory, send ./
my $datapath=$ARGV[2];
#"./";

# Parse(Read) in the spreadsheet
my $oBook = $oExcel->Parse($datapath.$ARGV[0]); 
my $Rcv = 0;

# Split filename up
my @filesplit = split /\./,$ARGV[0];

# export the file into a csv file format
#my $Sheet = $Book->Worksheets(1);
#$oWkS = $oBook->{Worksheet}[0]
#$oWkS = $oBook->{Worksheet}[0];
#foreach $oWkS (@{$oBook->{Worksheet}}) { 
   $oWkS = $oBook->{Worksheet}[0];
   # check to see if the worksheet has any data, if yes then process
   if (defined $oWkS->{MaxRow}) 
   {
      $filename = $datapath . @filesplit[0] . ".csv";
      open(OUT, ">" . $filename) || die "Could not open ".$filename."\n";    
      
      for(my $xcount = $oWkS->{MinRow}; 
         defined $oWkS->{MaxRow} && $xcount <= $oWkS->{MaxRow}; $xcount++) { 
         if ( $xcount <= $ARGV[1] ) {
             next;
         }
         #for(my $ycount = $oWkS->{MinCol} ; 
         for(my $ycount = 0 ; 
            defined $oWkS->{MaxCol} && $ycount <= $oWkS->{MaxCol} ; $ycount++) { 
                $oWkC = $oWkS->{Cells}[$xcount][$ycount]; 
                print OUT $oWkC->Value, if($oWkC); 
                print OUT "|", if($ycount < $oWkS->{MaxCol});
         }  # end columns for
         print OUT "\n";
      } #end rows for
      close(OUT);
   } # end if
#} # end foreach worksheet

# make a copy of the file for loading
#my $loadfile=$datapath . $ARGV[0] . $ARGV[1] . ".csv";
#copy($filename, $loadfile);
ASKER CERTIFIED SOLUTION
Avatar of szlamp
szlampFlag of United Kingdom of Great Britain and Northern Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answers