如何将.xls文件转换成.csv文件? [英] How to convert .xls file to .csv file?

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

问题描述

如何在perl中将 .xls 转换为 .csv ?这是什么模块?有什么例子吗?
什么是最好的转换方式?

How to convert .xls to .csv in perl? what is the module for this? Is there any example for this? what is the best way to convert?

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.

推荐答案

您的代码中有拼写错误。

You have typos in your code.

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

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

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

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