-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_excel_answersheet.pl
executable file
·53 lines (48 loc) · 1.64 KB
/
check_excel_answersheet.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/opt/local/bin/perl
use Spreadsheet::ParseExcel;
use Data::Dumper;
my $xls = new Spreadsheet::ParseExcel;
my $book = $xls->Parse('/Users/shantanoo/Downloads/Answers.xls') || die(":(((");
for($sheet=0;$sheet<$book->{SheetCount};$sheet++) {
$wks = $book->{Worksheet}[$sheet];
my $ques = 1;
for($iR = $wks->{MinRow}; defined $wks->{MaxRow} && $iR <= $wks->{MaxRow}; $iR++) {
$data = $wks->{Cells}[$iR][4];
if($data->{Val} =~ /^[A-Z]$/) {
$answer->{$sheet}->{$ques} = $data->{Val};
$ques++;
}
}
}
@names = `ls /Users/shantanoo/Downloads/answers`;
chomp @names;
foreach my $name (@names) {
print "$name\n";
my $x= calculate($answer, "/Users/shantanoo/Downloads/answers/".$name);
foreach $key (sort(keys(%{$x}))) {
print sprintf ("\t%10s ---> %s\n",$key, $x->{$key});
}
print "\n\n";
}
sub calculate {
my $answers = shift;
my $file = shift;
my $xls = new Spreadsheet::ParseExcel;
my $book = $xls->Parse($file);
my $score;
my @sheet_name = qw/Basic Word Excel PowerPoint/;
my @marks = qw/2 1.5 1.5 2/;
for($sheet=0;$sheet<$book->{SheetCount};$sheet++) {
$wks = $book->{Worksheet}[$sheet];
my $ques = 1;
for($iR = $wks->{MinRow}; defined $wks->{MaxRow} && $iR <= $wks->{MaxRow}; $iR++) {
$data = $wks->{Cells}[$iR][4];
if($data->{Val} =~ /^[A-Z]$/) {
$score->{$sheet_name[$sheet]} += int($marks[$sheet]) if($answers->{$sheet}->{$ques} eq $data->{Val});
$ques++;
}
}
}
$score->{total} += $score->{$sheet_name[$_]} for(0..3);
return($score);
}