tags:

views:

53

answers:

1

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

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);
  }
 }
}
A: 

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';
ysth