line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Spreadsheet::DataFromExcel; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
196091
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
91
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.001003'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1777
|
use Spreadsheet::ParseExcel; |
|
2
|
|
|
|
|
87872
|
|
|
2
|
|
|
|
|
933
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
1
|
15
|
sub new { bless {}, shift } |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub load { |
13
|
1
|
|
|
1
|
1
|
1426
|
my ( $self, $file, $sheet_name, $start_row, $end_row ) = @_; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
5
|
$self->error( undef ); |
16
|
|
|
|
|
|
|
|
17
|
1
|
50
|
|
|
|
22
|
return $self->_set_error("File $file not found") |
18
|
|
|
|
|
|
|
unless -e $file; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
|
|
9
|
my $parser = Spreadsheet::ParseExcel->new(); |
21
|
1
|
50
|
|
|
|
4240
|
my $workbook = $parser->Parse($file) |
22
|
|
|
|
|
|
|
or return $self->_set_error("Could not load Excel file; perhaps it's not a real Excel file or is damaged?"); |
23
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
11501
|
my $worksheet = defined $sheet_name |
25
|
|
|
|
|
|
|
? $workbook->Worksheet($sheet_name) |
26
|
|
|
|
|
|
|
: ($workbook->worksheets)[0]; |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
11
|
unless ( defined $worksheet ) { |
29
|
0
|
0
|
|
|
|
0
|
if ( defined $sheet_name ) { |
30
|
0
|
|
|
|
|
0
|
return $self->_set_error("Specified worksheet $sheet_name was not found in the Excel file"); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
0
|
|
|
|
|
0
|
return $self->_set_error("Could not obtain any worksheets"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
2
|
my @data; |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
5
|
my ( $row_min, $row_max ) = $worksheet->row_range; |
40
|
1
|
50
|
|
|
|
12
|
$row_min = $start_row |
41
|
|
|
|
|
|
|
if defined $start_row; |
42
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
4
|
$row_max = $end_row |
44
|
|
|
|
|
|
|
if defined $end_row; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
5
|
my ( $col_min, $col_max ) = $worksheet->col_range; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
10
|
for my $row ( $row_min .. $row_max ) { |
49
|
3
|
|
|
|
|
5
|
my @row; |
50
|
3
|
|
|
|
|
5
|
for my $col ( $col_min .. $col_max ) { |
51
|
12
|
|
|
|
|
48
|
my $cell = $worksheet->get_cell( $row, $col ); |
52
|
12
|
100
|
|
|
|
115
|
unless ( $cell ) { |
53
|
4
|
|
|
|
|
6
|
push @row, undef; |
54
|
4
|
|
|
|
|
8
|
next; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
8
|
|
|
|
|
21
|
push @row, $cell->unformatted; |
58
|
|
|
|
|
|
|
} |
59
|
3
|
|
|
|
|
16
|
push @data, \@row; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
20
|
return \@data; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _set_error { |
66
|
0
|
|
|
0
|
|
0
|
my ( $self, $error ) = @_; |
67
|
0
|
|
|
|
|
0
|
$self->error( $error ); |
68
|
0
|
|
|
|
|
0
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub error { |
72
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
8
|
@_ and $self->{ERROR} = shift; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
return $self->{ERROR}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |
80
|
|
|
|
|
|
|
__END__ |