converting .xls file to .csv file? [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:38:10

问题


My perl script for converting .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's 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! at csv.pl line 23.

Throwing error. What is the wrong in my code? Please find the error going in my code. Thanks in advance.


回答1:


You have a typo:

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

Use strict and warnings and you got warnings during compile time.

use strict;
use warnings;

You have typos:

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

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

Regards,



来源:https://stackoverflow.com/questions/21772377/converting-xls-file-to-csv-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!