如何修改此perl代码以从.xls文件中获取正确的信息

时间:2010-09-13 14:41:20

标签: perl

我想用以下条件修改此代码: 输入日期,并通知所有事件将在未来三或四天内到来。 请帮助我:(

#!/usr/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;

my $oExcel = new Spreadsheet::ParseExcel;

die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;

my $oBook = $oExcel->Parse($ARGV[0]);
my($iR, $iC, $oWkS, $oWkC);
print "FILE  :", $oBook->{File} , "\n";
print "COUNT :", $oBook->{SheetCount} , "\n";

print "AUTHOR:", $oBook->{Author} , "\n"
 if defined $oBook->{Author};

for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++)
{
 $oWkS = $oBook->{Worksheet}[$iSheet];
 print "--------- SHEET:", $oWkS->{Name}, "\n";

 for(my $iR = $oWkS->{MinRow} ;
     defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ;
     $iR++)

 {
  for(my $iC = $oWkS->{MinCol} ;
      defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ;
      $iC++)

  {
   $oWkC = $oWkS->{Cells}[$iR][$iC];
   print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);
  }
 }
}

1 个答案:

答案 0 :(得分:0)

我猜每一行都是一个事件?如果是这样,则不是每行的列上的内部循环,而是获取作为日期的特定列。如果它被Excel格式化为日期, 你可以这样做:

my $dateColumn = 3; # for example; 0 for column A, 1 for B, etc.
my $cell = $oWkS->{'Cells'}[$iR][$dateColumn]
my $date = Spreadsheet::ParseExcel::Utility::ExcelFmt( 'YYYY-MM-DD', $cell->unformatted(), $oBook->{'Flg1904'} );

然后只需查看您的日期是否在所需范围内或跳过该行:

next if $date lt '2010-09-13' || $date gt '2010-09-17';