将.xls文件转换为.csv文件? [英] converting .xls file to .csv file?

查看:210
本文介绍了将.xls文件转换为.csv文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用于将.xls转换为.csv的perl脚本

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;
}

at csv.pl line 23。

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.

推荐答案

您有拼写错误:

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

使用严格和警告,并且在编译期间出现警告。

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

use strict;
use warnings;

您有拼写错误:

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

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

非常感谢,

这篇关于将.xls文件转换为.csv文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆