如何使用简单的检查条件使用perl脚本读取excel表

时间:2015-03-24 18:02:10

标签: perl

我是新的蜜蜂到perl尝试阅读简单条件的excel表。

问题是读取所有记录并检查b列是否具有“始终为空”字符串,如果是,则显示列“C”的输出

示例:For Always Null condtion

预期输出:a,b,c,f,g

enter image description here

1 个答案:

答案 0 :(得分:2)

#!/usr/bin/perl 

use strict;
use warnings;
use v5.14;

use Spreadsheet::ParseExcel;
use Data::Dumper;

my $ws = Spreadsheet::ParseExcel
                ->new()
                ->parse('yourfile.xls')
                ->worksheet(0);

my ($i, $r_max) = $ws->row_range;

my ($cell_B, $cell_C);

while ($i <= $r_max) {
    $cell_B = $ws->get_cell($i,1);
    $cell_C = $ws->get_cell($i,2);

    say $cell_C->value 
        if $cell_B 
            and $cell_C 
            and $cell_B->value eq 'Always null';
} continue { $i++ }