从perl中的excel读取数据

时间:2017-02-08 08:03:09

标签: perl

我正在尝试从excel读取数据,我的代码如下。

    #!/usr/bin/perl
    use strict;
    use warnings;
    use 5.010;
    use feature 'say';
    use Spreadsheet::XLSX;
    use Spreadsheet::Read qw(ReadData);
    my $book = ReadData ('/tmp/simple.xlsx');

    say 'A1: ' . $book->[1]{A1};

    my @row = Spreadsheet::Read::row($book->[1], 1);
    for my $i (0 .. $#row) {
        say 'A' . ($i+1) . ' ' . ($row[$i] // '');
    }

    my @rows = Spreadsheet::Read::rows($book->[1]);
    foreach my $i (1 .. scalar @rows) {
        foreach my $j (1 .. scalar @{$rows[$i-1]}) {
        say chr(64+$i) . " $j " . ($rows[$i-1][$j-1] // '');
        }
    }

将错误视为:

        Can't locate OLE/Storage_Lite.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Spreadsheet/ParseExcel.pm line 21.
    BEGIN failed--compilation aborted at /usr/local/share/perl5/Spreadsheet/ParseExcel.pm line 21.
    Compilation failed in require at /usr/local/share/perl5/Spreadsheet/XLSX.pm line 14.
    BEGIN failed--compilation aborted at /usr/local/share/perl5/Spreadsheet/XLSX.pm line 14.
    Compilation failed in require at read_excel.pl line 6.
    BEGIN failed--compilation aborted at read_excel.pl line 6.

我有各种相关模块。但是当我要从CPAN下载OLE / Storage_Lite.pm时,如果出现错误,页面将变为空白,并且从下面的metacpan错误即将发生。

        https://cpan.metacpan.org/authors/id/M/MS/MSCHWARTZ/OLE-Storage-0.386.tar.gz
    Resolving cpan.metacpan.org... 151.101.128.249, 151.101.192.249, 151.101.64.249, ...
    Connecting to cpan.metacpan.org|151.101.128.249|:443... connected.
    ERROR: certificate common name “a.ssl.fastly.net” doesn’t match requested host name “cpan.metacpan.org”.
    To connect to cpan.metacpan.org insecurely, use ‘--no-check-certificate’.

1 个答案:

答案 0 :(得分:1)

尝试从cpanmetacpan下载模块tar zip。然后使用任何make实用程序(例如,makemake)在本地构建模块。您可以在here找到本地构建模块的更多信息。