开发者

how to modify this perl code to get right information from .xls files

开发者 https://www.devze.com 2023-01-16 10:58 出处:网络
I want to modify this code with these conditions : input a date, and notify all events will come in next three or four... days.

I want to modify this code with these conditions : input a date, and notify all events will come in next three or four... days. plz help me :(

#!/usr/bin/perl -w

us开发者_JS百科e 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);
  }
 }
}


I'm guessing each row is an event? If so, instead of the inner loop over the columns for each row, get the particular column that is the date. If it is formatted by Excel as a date, you can do this with:

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'} );

Then simply see if your date is in the desired range or skip the row:

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

精彩评论

暂无评论...
验证码 换一张
取 消