ParseExcel/Worksheet.pm

filter: Statementstmt 89.5% 120 / 134 Branchbran 50.0% 16 / 32 Conditioncond 36.3% 8 / 22 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 95.4% 42 / 44 Podpod 94.7% 36 / 38 totaltotal 79.2% 222 / 280 CC 25 SCAR 16.8
CC
25
Cov
77%
get_cell
25.9
is_row_hidden
6.0
is_col_hidden
6.0
CRAP 5.4
« ParseExcel/FmtJapan2.pm ↑ Summary ParseExcel/SaveParser.pm »
1 package Spreadsheet::ParseExcel::Worksheet;
2  
3 ###############################################################################
4 #
5 # Spreadsheet::ParseExcel::Worksheet - A class for Worksheets.
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 21 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 21 our $VERSION = '0.66';
24  
25 ###############################################################################
26 #
27 # new()
28 #
29 87 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
30  
31 87 my ( $class, %properties ) = @_;
32  
33 87 my $self = \%properties;
34  
35 87 weaken $self->{_Book};
36  
37 87 $self->{Cells} = undef;
38 87 $self->{DefColWidth} = 8.43;
39  
40 87 return bless $self, $class;
41 }
42  
43 ###############################################################################
44 #
45 # get_cell( $row, $col )
46 #
47 # Returns the Cell object at row $row and column $col, if defined.
48 #
49 267 ▶sub get_cell {
Subroutine get_cell: called CC=9 SCAR=32.5
Pod documented
50  
51 267 my ( $self, $row, $col ) = @_;
52  
53 267 ▶ if ( !defined $row
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $row && defined $col && defined $self->{'MaxRow'} && defined $self->{'MaxCol'}) { } 0 267 267
elsif ($row < $self->{'MinRow'} or $row > $self->{'MaxRow'} or $col < $self->{'MinCol'} or $col > $self->{'MaxCol'}) { } 0 267 267
Condition33%3/9
defined $row && defined $col && defined $self->{'MaxRow'} && defined $self->{'MaxCol'}
!ll&&!rl&&r
00267
defined $row and defined $col and defined $self->{"MaxRow"}
!ll&&!rl&&r
00267
defined $row and defined $col
!ll&&!rl&&r
00267
MC/DC0%0/4
defined $row && defined $col && defined $self->{'MaxRow'} && defined $self->{'MaxCol'}
defined $row defined $col defined $self->{"MaxRow"} defined $self->{'MaxCol'}
Truth table20%1/5
A and B and C && D
A= defined $rowB= defined $colC= defined $self->{"MaxRow"}D= defined $self->{'MaxCol'}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
54 || !defined $col
55 || !defined $self->{MaxRow}
56 || !defined $self->{MaxCol} )
57 {
58  
59 # Return undef if no arguments are given or if no cells are defined.
60 0 return undef;
61 }
62 ▶ elsif ($row < $self->{MinRow}
Condition33%3/9
$row < $self->{"MinRow"} or $row > $self->{"MaxRow"} or $col < $self->{"MinCol"} or $col > $self->{"MaxCol"}
l!l&&r!l&&!r
00267
$row < $self->{"MinRow"} or $row > $self->{"MaxRow"} or $col < $self->{"MinCol"}
l!l&&r!l&&!r
00267
$row < $self->{"MinRow"} or $row > $self->{"MaxRow"}
l!l&&r!l&&!r
00267
MC/DC0%0/4
$row < $self->{"MinRow"} or $row > $self->{"MaxRow"} or $col < $self->{"MinCol"} or $col > $self->{"MaxCol"}
$row < $self->{"MinRow"} $row > $self->{"MaxRow"} $col < $self->{"MinCol"} $col > $self->{"MaxCol"}
Truth table20%1/5
A or B or C or D
A= $row < $self->{"MinRow"}B= $row > $self->{"MaxRow"}C= $col < $self->{"MinCol"}D= $col > $self->{"MaxCol"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
63 || $row > $self->{MaxRow}
64 || $col < $self->{MinCol}
65 || $col > $self->{MaxCol} )
66 {
67  
68 # Return undef if outside allowable row/col range.
69 0 return undef;
70 }
71 else {
72  
73 # Return the Cell object.
74 267 return $self->{Cells}->[$row]->[$col];
75 }
76 }
77  
78 ###############################################################################
79 #
80 # row_range()
81 #
82 # Returns a two-element list ($min, $max) containing the minimum and maximum
83 # defined rows in the worksheet.
84 #
85 # If there is no row defined $max is smaller than $min.
86 #
87 15 ▶sub row_range {
Subroutine row_range: called CC=3 SCAR=11.4
Pod documented
88  
89 15 my $self = shift;
90  
91 15 ▶ my $min = $self->{MinRow} || 0;
Condition50%1/2
$self->{'MinRow'} || 0
l!l
015
MC/DC0%0/1
$self->{'MinRow'} || 0
$self->{'MinRow'}
Truth table50%1/2
A
A= $self->{'MinRow'}
Aresult
11
00
92 15 ▶ my $max = defined( $self->{MaxRow} ) ? $self->{MaxRow} : ( $min - 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MaxRow'} ? : 15 0 15
93  
94 15 return ( $min, $max );
95 }
96  
97 ###############################################################################
98 #
99 # col_range()
100 #
101 # Returns a two-element list ($min, $max) containing the minimum and maximum
102 # defined cols in the worksheet.
103 #
104 # If there is no column defined $max is smaller than $min.
105 #
106 15 ▶sub col_range {
Subroutine col_range: called CC=3 SCAR=11.4
Pod documented
107  
108 15 my $self = shift;
109  
110 15 ▶ my $min = $self->{MinCol} || 0;
Condition50%1/2
$self->{'MinCol'} || 0
l!l
015
MC/DC0%0/1
$self->{'MinCol'} || 0
$self->{'MinCol'}
Truth table50%1/2
A
A= $self->{'MinCol'}
Aresult
11
00
111 15 ▶ my $max = defined( $self->{MaxCol} ) ? $self->{MaxCol} : ( $min - 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'MaxCol'} ? : 15 0 15
112  
113 15 return ( $min, $max );
114 }
115  
116 ###############################################################################
117 #
118 # get_name()
119 #
120 # Returns the name of the worksheet.
121 #
122 11 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod documented
123  
124 11 my $self = shift;
125  
126 11 return $self->{Name};
127 }
128  
129 ###############################################################################
130 #
131 # sheet_num()
132 #
133 2 ▶sub sheet_num {
Subroutine sheet_num: called CC=1 SCAR=0.0
Pod undocumented
134  
135 2 my $self = shift;
136  
137 2 return $self->{_SheetNo};
138 }
139  
140 ###############################################################################
141 #
142 # get_h_pagebreaks()
143 #
144 # Returns an array ref of row numbers where a horizontal page break occurs.
145 #
146 2 ▶sub get_h_pagebreaks {
Subroutine get_h_pagebreaks: called CC=1 SCAR=0.0
Pod documented
147  
148 2 my $self = shift;
149  
150 2 return $self->{HPageBreak};
151 }
152  
153 ###############################################################################
154 #
155 # get_v_pagebreaks()
156 #
157 # Returns an array ref of column numbers where a vertical page break occurs.
158 #
159 2 ▶sub get_v_pagebreaks {
Subroutine get_v_pagebreaks: called CC=1 SCAR=0.0
Pod documented
160  
161 2 my $self = shift;
162  
163 2 return $self->{VPageBreak};
164 }
165  
166 ###############################################################################
167 #
168 # get_merged_areas()
169 #
170 # Returns an array ref of cells that are merged.
171 #
172 2 ▶sub get_merged_areas {
Subroutine get_merged_areas: called CC=1 SCAR=0.0
Pod documented
173  
174 2 my $self = shift;
175  
176 2 return $self->{MergedArea};
177 }
178  
179 ###############################################################################
180 #
181 # get_row_heights()
182 #
183 # Returns an array of row heights.
184 #
185 3 ▶sub get_row_heights {
Subroutine get_row_heights: called CC=3 SCAR=11.8
Pod documented
186  
187 3 my $self = shift;
188  
189 3 ▶ if ( wantarray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 3 0 3
190 3 ▶ return unless $self->{RowHeight};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RowHeight"} 0 3 3
191 3 return @{ $self->{RowHeight} };
192 }
193 0 return $self->{RowHeight};
194 }
195  
196 ###############################################################################
197 #
198 # get_col_widths()
199 #
200 # Returns an array of column widths.
201 #
202 3 ▶sub get_col_widths {
Subroutine get_col_widths: called CC=3 SCAR=11.8
Pod documented
203  
204 3 my $self = shift;
205  
206 3 ▶ if ( wantarray() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 3 0 3
207 3 ▶ return unless $self->{ColWidth};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ColWidth"} 0 3 3
208 3 return @{ $self->{ColWidth} };
209 }
210 0 return $self->{ColWidth};
211 }
212  
213 ###############################################################################
214 #
215 # get_default_row_height()
216 #
217 # Returns the default row height for the worksheet. Generally 12.75.
218 #
219 2 ▶sub get_default_row_height {
Subroutine get_default_row_height: called CC=1 SCAR=0.0
Pod documented
220  
221 2 my $self = shift;
222  
223 2 return $self->{DefRowHeight};
224 }
225  
226 ###############################################################################
227 #
228 # get_default_col_width()
229 #
230 # Returns the default column width for the worksheet. Generally 8.43.
231 #
232 2 ▶sub get_default_col_width {
Subroutine get_default_col_width: called CC=1 SCAR=0.0
Pod documented
233  
234 2 my $self = shift;
235  
236 2 return $self->{DefColWidth};
237 }
238  
239 ###############################################################################
240 #
241 # _get_row_properties()
242 #
243 # Returns an array_ref of row properties.
244 # TODO. This is a placeholder for a future method.
245 #
246 0 ▶sub _get_row_properties {
Subroutine _get_row_properties: not called CC=1 SCAR=6.9
247  
248 0 my $self = shift;
249  
250 0 return $self->{RowProperties};
251 }
252  
253 ###############################################################################
254 #
255 # _get_col_properties()
256 #
257 # Returns an array_ref of column properties.
258 # TODO. This is a placeholder for a future method.
259 #
260 0 ▶sub _get_col_properties {
Subroutine _get_col_properties: not called CC=1 SCAR=6.9
261  
262 0 my $self = shift;
263  
264 0 return $self->{ColProperties};
265 }
266  
267 ###############################################################################
268 #
269 # get_header()
270 #
271 # Returns the worksheet header string.
272 #
273 2 ▶sub get_header {
Subroutine get_header: called CC=1 SCAR=0.0
Pod documented
274  
275 2 my $self = shift;
276  
277 2 return $self->{Header};
278 }
279  
280 ###############################################################################
281 #
282 # get_footer()
283 #
284 # Returns the worksheet footer string.
285 #
286 2 ▶sub get_footer {
Subroutine get_footer: called CC=1 SCAR=0.0
Pod documented
287  
288 2 my $self = shift;
289  
290 2 return $self->{Footer};
291 }
292  
293 ###############################################################################
294 #
295 # get_margin_left()
296 #
297 # Returns the left margin of the worksheet in inches.
298 #
299 2 ▶sub get_margin_left {
Subroutine get_margin_left: called CC=1 SCAR=0.0
Pod documented
300  
301 2 my $self = shift;
302  
303 2 return $self->{LeftMargin};
304 }
305  
306 ###############################################################################
307 #
308 # get_margin_right()
309 #
310 # Returns the right margin of the worksheet in inches.
311 #
312 2 ▶sub get_margin_right {
Subroutine get_margin_right: called CC=1 SCAR=0.0
Pod documented
313  
314 2 my $self = shift;
315  
316 2 return $self->{RightMargin};
317 }
318  
319 ###############################################################################
320 #
321 # get_margin_top()
322 #
323 # Returns the top margin of the worksheet in inches.
324 #
325 2 ▶sub get_margin_top {
Subroutine get_margin_top: called CC=1 SCAR=0.0
Pod documented
326  
327 2 my $self = shift;
328  
329 2 return $self->{TopMargin};
330 }
331  
332 ###############################################################################
333 #
334 # get_margin_bottom()
335 #
336 # Returns the bottom margin of the worksheet in inches.
337 #
338 2 ▶sub get_margin_bottom {
Subroutine get_margin_bottom: called CC=1 SCAR=0.0
Pod documented
339  
340 2 my $self = shift;
341  
342 2 return $self->{BottomMargin};
343 }
344  
345 ###############################################################################
346 #
347 # get_margin_header()
348 #
349 # Returns the header margin of the worksheet in inches.
350 #
351 2 ▶sub get_margin_header {
Subroutine get_margin_header: called CC=1 SCAR=0.0
Pod documented
352  
353 2 my $self = shift;
354  
355 2 return $self->{HeaderMargin};
356 }
357  
358 ###############################################################################
359 #
360 # get_margin_footer()
361 #
362 # Returns the footer margin of the worksheet in inches.
363 #
364 2 ▶sub get_margin_footer {
Subroutine get_margin_footer: called CC=1 SCAR=0.0
Pod documented
365  
366 2 my $self = shift;
367  
368 2 return $self->{FooterMargin};
369 }
370  
371 ###############################################################################
372 #
373 # get_paper()
374 #
375 # Returns the printer paper size.
376 #
377 2 ▶sub get_paper {
Subroutine get_paper: called CC=1 SCAR=0.0
Pod documented
378  
379 2 my $self = shift;
380  
381 2 return $self->{PaperSize};
382 }
383  
384 ###############################################################################
385 #
386 # get_start_page()
387 #
388 # Returns the page number that printing will start from.
389 #
390 4 ▶sub get_start_page {
Subroutine get_start_page: called CC=2 SCAR=6.9
Pod documented
391  
392 4 my $self = shift;
393  
394 # Only return the page number if the "First page number" option is set.
395 4 ▶ if ( $self->{UsePage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'UsePage'}) { } 2 2 4
396 2 return $self->{PageStart};
397 }
398 else {
399 2 return 0;
400 }
401 }
402  
403 ###############################################################################
404 #
405 # get_print_order()
406 #
407 # Returns the Worksheet page printing order.
408 #
409 2 ▶sub get_print_order {
Subroutine get_print_order: called CC=1 SCAR=0.0
Pod documented
410  
411 2 my $self = shift;
412  
413 2 return $self->{LeftToRight};
414 }
415  
416 ###############################################################################
417 #
418 # get_print_scale()
419 #
420 # Returns the workbook scale for printing.
421 #
422 2 ▶sub get_print_scale {
Subroutine get_print_scale: called CC=1 SCAR=0.0
Pod documented
423  
424 2 my $self = shift;
425  
426 2 return $self->{Scale};
427 }
428  
429 ###############################################################################
430 #
431 # get_fit_to_pages()
432 #
433 # Returns the number of pages wide and high that the printed worksheet page
434 # will fit to.
435 #
436 6 ▶sub get_fit_to_pages {
Subroutine get_fit_to_pages: called CC=2 SCAR=6.9
Pod documented
437  
438 6 my $self = shift;
439  
440 6 ▶ if ( !$self->{PageFit} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{'PageFit'}) { } 3 3 6
441 3 return ( 0, 0 );
442 }
443 else {
444 3 return ( $self->{FitWidth}, $self->{FitHeight} );
445 }
446 }
447  
448 ###############################################################################
449 #
450 # is_portrait()
451 #
452 # Returns true if the worksheet has been set for printing in portrait mode.
453 #
454 2 ▶sub is_portrait {
Subroutine is_portrait: called CC=1 SCAR=0.0
Pod documented
455  
456 2 my $self = shift;
457  
458 2 return $self->{Landscape};
459 }
460  
461 ###############################################################################
462 #
463 # is_centered_horizontally()
464 #
465 # Returns true if the worksheet has been centered horizontally for printing.
466 #
467 2 ▶sub is_centered_horizontally {
Subroutine is_centered_horizontally: called CC=1 SCAR=0.0
Pod documented
468  
469 2 my $self = shift;
470  
471 2 return $self->{HCenter};
472 }
473  
474 ###############################################################################
475 #
476 # is_centered_vertically()
477 #
478 # Returns true if the worksheet has been centered vertically for printing.
479 #
480 2 ▶sub is_centered_vertically {
Subroutine is_centered_vertically: called CC=1 SCAR=0.0
Pod documented
481  
482 2 my $self = shift;
483  
484 2 return $self->{HCenter};
485 }
486  
487 ###############################################################################
488 #
489 # is_print_gridlines()
490 #
491 # Returns true if the worksheet print "gridlines" option is turned on.
492 #
493 2 ▶sub is_print_gridlines {
Subroutine is_print_gridlines: called CC=1 SCAR=0.0
Pod documented
494  
495 2 my $self = shift;
496  
497 2 return $self->{PrintGrid};
498 }
499  
500 ###############################################################################
501 #
502 # is_print_row_col_headers()
503 #
504 # Returns true if the worksheet print "row and column headings" option is on.
505 #
506 2 ▶sub is_print_row_col_headers {
Subroutine is_print_row_col_headers: called CC=1 SCAR=0.0
Pod documented
507  
508 2 my $self = shift;
509  
510 2 return $self->{PrintHeaders};
511 }
512  
513 ###############################################################################
514 #
515 # is_print_black_and_white()
516 #
517 # Returns true if the worksheet print "black and white" option is turned on.
518 #
519 2 ▶sub is_print_black_and_white {
Subroutine is_print_black_and_white: called CC=1 SCAR=0.0
Pod documented
520  
521 2 my $self = shift;
522  
523 2 return $self->{NoColor};
524 }
525  
526 ###############################################################################
527 #
528 # is_print_draft()
529 #
530 # Returns true if the worksheet print "draft" option is turned on.
531 #
532 2 ▶sub is_print_draft {
Subroutine is_print_draft: called CC=1 SCAR=0.0
Pod documented
533  
534 2 my $self = shift;
535  
536 2 return $self->{Draft};
537 }
538  
539 ###############################################################################
540 #
541 # is_print_comments()
542 #
543 # Returns true if the worksheet print "comments" option is turned on.
544 #
545 2 ▶sub is_print_comments {
Subroutine is_print_comments: called CC=1 SCAR=0.0
Pod documented
546  
547 2 my $self = shift;
548  
549 2 return $self->{Notes};
550 }
551  
552 =head2 get_tab_color()
553  
554 Return color index of tab, or undef if not set.
555  
556 =cut
557  
558 1 ▶sub get_tab_color {
Subroutine get_tab_color: called CC=1 SCAR=0.0
Pod documented
559 1 my $worksheet = shift;
560  
561 1 return $worksheet->{TabColor};
562 }
563  
564 =head2 is_sheet_hidden()
565  
566 Return true if sheet is hidden
567  
568 =cut
569  
570 2 ▶sub is_sheet_hidden {
Subroutine is_sheet_hidden: called CC=1 SCAR=0.0
Pod documented
571 2 my $worksheet = shift;
572  
573 2 return $worksheet->{SheetHidden};
574 }
575  
576 =head2 is_row_hidden($row)
577  
578 In scalar context, return true if $row is hidden
579 In array context, return an array whose elements are true
580 if the corresponding row is hidden.
581  
582 =cut
583  
584 2 ▶sub is_row_hidden {
Subroutine is_row_hidden: called CC=4 SCAR=17.9
Pod documented
585 2 my $worksheet = shift;
586  
587 2 my ($row) = @_;
588  
589 2 ▶ unless ( $worksheet->{RowHidden} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($worksheet->{"RowHidden"}) 0 2 2
590 0 ▶ return () if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
591 0 return 0;
592 }
593  
594 0 ▶ return @{ $worksheet->{RowHidden} } if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 2 2
595 2 return $worksheet->{RowHidden}[$row];
596 }
597  
598 =head2 is_col_hidden($col)
599  
600 In scalar context, return true if $col is hidden
601 In array context, return an array whose elements are true
602 if the corresponding column is hidden.
603  
604 =cut
605  
606 2 ▶sub is_col_hidden {
Subroutine is_col_hidden: called CC=4 SCAR=17.9
Pod documented
607 2 my $worksheet = shift;
608  
609 2 my ($col) = @_;
610  
611 2 ▶ unless ( $worksheet->{ColHidden} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($worksheet->{"ColHidden"}) 0 2 2
612 0 ▶ return () if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
613 0 return 0;
614 }
615  
616 0 ▶ return @{ $worksheet->{ColHidden} } if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 2 2
617 2 return $worksheet->{ColHidden}[$col];
618 }
619  
620 ###############################################################################
621 #
622 # Mapping between legacy method names and new names.
623 #
624 {
625 21 ▶ no warnings; # Ignore warnings about variables used only once.
Subroutine BEGIN: called CC=1 SCAR=0.0
626 21 *sheetNo = *sheet_num;
627 21 *Cell = *get_cell;
628 21 *RowRange = *row_range;
629 21 *ColRange = *col_range;
630 }
631  
632 21 1;
633  
634 __END__
« ParseExcel/FmtJapan2.pm ↑ Summary ParseExcel/SaveParser.pm »