首页 > 解决方案 > 从 xlsx 读取单元格并进行比较

问题描述

我第一次尝试使用 perl 来使用 xlsx。即使单元格包含 1'b1 或 1'b0,else 条件也会始终执行。请帮帮我。

#!/usr/bin/perl -w

use Spreadsheet::ParseXLSX;
use Spreadsheet::WriteExcel;
use Switch;

 # Creates object (parser) of ParseXLSX 
 my $parser = Spreadsheet::ParseXLSX->new();

 # call parse method thro parser object for parsing and parse it to excel variable
 $excel = $parser->parse('PinMux_Spec.xlsx');

#$test_cond = "TEST.mbist_mode == 1'b0 && DIG_PINMUX.FC_pti_en == 1'b1";
$file_func = "pinmux_func.csv";

open (FH_F,">$file_func") || die "cannot open $file_func\n";  
# looping thro all the sheets in .xlsx sheet
foreach $sheet (@{$excel -> {Worksheet}}) 
{
if(index ($sheet ->{Name},"FUNCTIONAL_MODE") !=-1 )  {
$sheetname = $sheet -> {Name};

# max row depth
$sheet -> {MaxRow} ||= $sheet -> {MinRow};            
$i=0;
# Row iteration outer loop ex cell[0][0], cell[1][0]..
foreach $row ($sheet -> {MinRow} .. $sheet -> {MaxRow}) 
{
  # max column depth    
  $sheet -> {MaxCol} ||= $sheet -> {MinCol};            
  $j=0; 

  # Column iteration inner loop ex. cell[0][0], cell[0][1]..
  foreach  $col ($sheet -> {MinCol} ..  $sheet -> {MaxCol}) 
  {
    # read content of cells in each row and column
    $cell       = $sheet -> {Cells} [$row] [$col];          
    $column[$j] = $cell-> {Val};
    $j++;
  }

#######   MAJOR CODE          ########
$OEN_SIGNAL             = $column[1];
print FH_F "$OEN_SIGNAL";
if($OEN_SIGNAL eq "1'b1")    {          print FH_F "A"; }
elsif($OEN_SIGNAL eq "1'b0") {          print FH_F "B"; }
else                         {          print FH_F "C"; }
}
}
}

实际输出

$OEN_SIGNAL-操作

1'b1-A

1'b0-B

sda_oen-C

标签: perlxlsx

解决方案


对不起,这是一个小错误。将 1b'1 更正为 1'b1 后,实际输出现在是正确的。我已经更正了代码和输出。我的问题解决了。我不知道是否将问题标记为已解决。所以就这样离开吧。


推荐阅读