eval "use Spreadsheet::ParseExcel;";
die $@ if $@;
+ eval "use DateTime::Format::Excel;";
+ #for now, just let the error be thrown if it is used, since only CDR
+ # formats bill_west and troop use it, not other excel-parsing things
+ #die $@ if $@;
+
my $excel = Spreadsheet::ParseExcel::Workbook->new->Parse($filename);
$parser = $excel->{Worksheet}[0]; #first sheet
#&{$field}(\%hash, $value);
push @later, $field, $value;
} else {
- $hash{$field} = $value if length($value);
+ $hash{$field} = $value if defined($value) && length($value);
}
}
return "can't insert record". ( $line ? " for $line" : '' ). ": $error";
}
+ $row++;
$imported++;
if ( $job && time - $min_sec > $last ) { #progress bar
# DATE / Yes / "DATE" Excel date format MM/DD/YYYY
sub { my($cdr, $date) = @_;
- $date =~ /^(\d{1,2})\/(\d{1,2})\/(\d\d(\d\d)?)$/
- or die "unparsable date: $date"; #maybe we shouldn't die...
- #$cdr->startdate( timelocal(0, 0, 0 ,$2, $1-1, $3) );
- ($tmp_mday, $tmp_mon, $tmp_year) = ( $2, $1-1, $3 );
+
+ #$date =~ /^(\d{1,2})\/(\d{1,2})\/(\d\d(\d\d)?)$/
+ # or die "unparsable date: $date"; #maybe we shouldn't die...
+ ##$cdr->startdate( timelocal(0, 0, 0 ,$2, $1-1, $3) );
+ #($tmp_mday, $tmp_mon, $tmp_year) = ( $2, $1-1, $3 );
+
+ my $datetime = DateTime::Format::Excel->parse_datetime( $date );
+ $tmp_mon = $datetime->mon_0;
+ $tmp_mday = $datetime->mday;
+ $tmp_year = $datetime->year;
},
# CUST NO / Yes / "TIME" "075959" Text based time
# is wrong
sub { my($cdr, $time) = @_;
#my($sec, $min, $hour, $mday, $mon, $year)= localtime($cdr->startdate);
- $time =~ /^(\d{1,2}):(\d{1,2}):(\d{1,2})$/
+ $time =~ /^(\d{2})(\d{2})(\d{2})$/
or die "unparsable time: $time"; #maybe we shouldn't die...
#$cdr->startdate( timelocal($3, $2, $1 ,$mday, $mon, $year) );
$cdr->startdate(