ParseExcel/Workbook.pm

filter: Statementstmt 93.8% 46 / 49 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 93.3% 14 / 15 Podpod 66.6% 8 / 12 totaltotal 87.8% 72 / 82 CC 5 SCAR 5.9
CC
5
Cov
91%
worksheet
4.1
color_idx_to_rgb
2.0
ParseAbort
2.0
CRAP 1.8
« ParseExcel/Cell.pm ↑ Summary ParseExcel/Font.pm »
1 package Spreadsheet::ParseExcel::Workbook;
2  
3 ###############################################################################
4 #
5 # Spreadsheet::ParseExcel::Workbook - A class for Workbooks.
6 #
7 # Used in conjunction with Spreadsheet::ParseExcel.
8 #
9 # Copyright (c) 2014 Douglas Wilson
10 # Copyright (c) 2009-2013 John McNamara
11 # Copyright (c) 2006-2008 Gabor Szabo
12 # Copyright (c) 2000-2006 Kawai Takanori
13 #
14 # perltidy with standard settings.
15 #
16 # Documentation after __END__
17 #
18  
19 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 21 our $VERSION = '0.66';
23  
24 ###############################################################################
25 #
26 # new()
27 #
28 # Constructor.
29 #
30 48 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
31 48 my ($class) = @_;
32 48 my $self = {};
33 48 bless $self, $class;
34 }
35  
36 ###############################################################################
37 1 ▶sub color_idx_to_rgb {
Subroutine color_idx_to_rgb: called CC=2 SCAR=7.1
Pod undocumented
38 1 my( $workbook, $iidx ) = @_;
39  
40 1 my $palette = $workbook->{aColor};
41 1 ▶ return ( ( defined $palette->[$iidx] ) ? $palette->[$iidx] : $palette->[0] );
Branch: 1 branch
BranchTrueFalseTotal
defined $palette->[$iidx] ? : 1 0 1
42 }
43  
44 ###############################################################################
45 #
46 # worksheet()
47 #
48 # This method returns a single Worksheet object using either its name or index.
49 #
50 118 ▶sub worksheet {
Subroutine worksheet: called CC=4 SCAR=14.0
Pod documented
51 118 my ( $oBook, $sName ) = @_;
52 118 my $oWkS;
53 118 foreach $oWkS ( @{ $oBook->{Worksheet} } ) {
54 213 ▶ return $oWkS if ( $oWkS->{Name} eq $sName );
Branch: 1 branch
BranchTrueFalseTotal
if $oWkS->{"Name"} eq $sName 81 132 213
55 }
56 37 ▶ if ( $sName =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sName =~ /^\d+$/) 37 0 37
57 37 return $oBook->{Worksheet}->[$sName];
58 }
59 0 return undef;
60 }
61  
62 ###############################################################################
63 #
64 # worksheets()
65 #
66 # Returns an array of Worksheet objects.
67 #
68 1 ▶sub worksheets {
Subroutine worksheets: called CC=1 SCAR=0.0
Pod documented
69 1 my $self = shift;
70  
71 1 return @{ $self->{Worksheet} };
72 }
73  
74 ###############################################################################
75 #
76 # worksheet_count()
77 #
78 # Returns the number Woksheet objects in the Workbook.
79 #
80 1 ▶sub worksheet_count {
Subroutine worksheet_count: called CC=1 SCAR=0.0
Pod documented
81  
82 1 my $self = shift;
83  
84 1 return $self->{SheetCount};
85 }
86  
87 ###############################################################################
88 #
89 # get_filename()
90 #
91 # Returns the name of the Excel file of C<undef> if the data was read from a filehandle rather than a file.
92 #
93 2 ▶sub get_filename {
Subroutine get_filename: called CC=1 SCAR=0.0
Pod documented
94  
95 2 my $self = shift;
96  
97 2 return $self->{File};
98 }
99  
100 ###############################################################################
101 #
102 # get_print_areas()
103 #
104 # Returns an array ref of print areas.
105 #
106 # TODO. This should really be a Worksheet method.
107 #
108 1 ▶sub get_print_areas {
Subroutine get_print_areas: called CC=1 SCAR=0.0
Pod documented
109  
110 1 my $self = shift;
111  
112 1 return $self->{PrintArea};
113 }
114  
115 ###############################################################################
116 #
117 # get_print_titles()
118 #
119 # Returns an array ref of print title hash refs.
120 #
121 # TODO. This should really be a Worksheet method.
122 #
123 1 ▶sub get_print_titles {
Subroutine get_print_titles: called CC=1 SCAR=0.0
Pod documented
124  
125 1 my $self = shift;
126  
127 1 return $self->{PrintTitle};
128 }
129  
130 ###############################################################################
131 #
132 # using_1904_date()
133 #
134 # Returns true if the Excel file is using the 1904 date epoch.
135 #
136 2 ▶sub using_1904_date {
Subroutine using_1904_date: called CC=1 SCAR=0.0
Pod documented
137  
138 2 my $self = shift;
139  
140 2 return $self->{Flg1904};
141 }
142  
143 ###############################################################################
144 #
145 # ParseAbort()
146 #
147 # Todo
148 #
149 0 ▶sub ParseAbort {
Subroutine ParseAbort: not called CC=1 SCAR=6.9
Pod undocumented
150 0 my ( $self, $val ) = @_;
151 0 $self->{_ParseAbort} = $val;
152 }
153  
154 =head2 get_active_sheet()
155  
156 Return the number of the active (open) worksheet (at the time the workbook
157 was saved. May return undef.
158  
159 =cut
160  
161 2 ▶sub get_active_sheet {
Subroutine get_active_sheet: called CC=1 SCAR=0.0
Pod documented
162 2 my $workbook = shift;
163  
164 2 return $workbook->{ActiveSheet};
165 }
166  
167 ###############################################################################
168 #
169 # Parse(). Deprecated.
170 #
171 # Syntactic wrapper around Spreadsheet::ParseExcel::Parse().
172 # This method is *deprecated* since it doesn't conform to the current
173 # error handling in the S::PE Parse() method.
174 #
175 9 ▶sub Parse {
Subroutine Parse: called CC=1 SCAR=0.0
Pod undocumented
176  
177 9 my ( $class, $source, $formatter ) = @_;
178 9 my $excel = Spreadsheet::ParseExcel->new();
179 9 my $workbook = $excel->Parse( $source, $formatter );
180 9 $workbook->{_Excel} = $excel;
181 9 return $workbook;
182 }
183  
184 ###############################################################################
185 #
186 # Mapping between legacy method names and new names.
187 #
188 {
189 21 ▶ no warnings; # Ignore warnings about variables used only once.
Subroutine BEGIN: called CC=1 SCAR=0.0
190 21 *Worksheet = *worksheet;
191 }
192  
193 21 1;
194  
195 __END__
« ParseExcel/Cell.pm ↑ Summary ParseExcel/Font.pm »