在Perl中解析Excel文件的最佳方式是什么? [英] What's the best way to parse Excel file in Perl?

查看:225
本文介绍了在Perl中解析Excel文件的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Perl中解析Excel文件的最简单方法是什么?将其转换为文本文件也可以正常工作。

What's the simplest way to parse an Excel file in Perl? Converting it to a text file would also work.

推荐答案

最好的方法是使用 Spreadsheet :: ParseExcel

这是一个例子:

#!/usr/bin/perl -w

use strict;
use warnings;

use Spreadsheet::ParseExcel;

my $parser   = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse('Book1.xls');

for my $worksheet ( $workbook->worksheets() ) {

    my ( $row_min, $row_max ) = $worksheet->row_range();
    my ( $col_min, $col_max ) = $worksheet->col_range();

    for my $row ( $row_min .. $row_max ) {
        for my $col ( $col_min .. $col_max ) {

            my $cell = $worksheet->get_cell( $row, $col );
            next unless $cell;

            print "Row, Col    = ($row, $col)\n";
            print "Value       = ", $cell->value(),       "\n";
            print "Unformatted = ", $cell->unformatted(), "\n";
            print "\n";
        }
    }
}

要将Excel文件转换为使用Perl的文本我建议使用Spreadsheet :: ParseExcel的 excel2txt

To convert an Excel file to text with Perl I'd recommend excel2txt which uses Spreadsheet::ParseExcel.

这篇关于在Perl中解析Excel文件的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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