Convert .xls file to CSV file?

My perl script to convert .xls to .csv

use Spreadsheet::ParseExcel;
my $xlsparser = Spreadsheet::ParseExcel->new();
my $xlsbook = $xlsparser->parse('/home/Admin/Downloads/abc.xls');
my $xls = $xlsbook->worksheet(0);
my ( $row_first, $row_last ) = $xls->row_range();
my ( $col_first, $col_last ) = $xls->col_range();
my $csv = '/home/Admin/Downloads/ram.csv';
for my $row ( $row_first .. $row_last ) {       # Step through each row
   for my $col ( $col_first .. $col_last ) {    # Step through each column
       my $cell = $xls->get_cell( $row, $col ); # Get the current cell
       next unless $cell;
       $csv .= $cell->unformatted(); # Get the cell raw data -- no border 
                                     # colors or anything like that
       if ($col == $col_last) {
           $csv .= "\n"; 
       } else {
           $csv .= ","; 
       }
   }
}
open(my$FH ,'>',"$csv") or die "oops!";

while (my$line = <$xlsbook>){
    print $FH $line;
}

oops! in line csv.pl 23.

Ejection error. What happened in my code? Please find the error in my code. Thanks in advance.

+1
source share
1 answer

You have a typo:

open(my $FH ,'>',"$csv") or die "oops!";

Use strict information and warnings, and you received warnings during compilation.

use strict;
use warnings;

You have typos:

open(my $FH ,'>',$csv) or die "oops!";

while (my$line = <$FH>){

Hi,

0
source

All Articles