| 1 | package Spreadsheet::ParseExcel::Simple; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | $VERSION = '1.04'; | |||||||||||
| 4 | |||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use Spreadsheet::ParseExcel; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | =head1 NAME | ||||||||||||
| 9 | |||||||||||||
| 10 | Spreadsheet::ParseExcel::Simple - A simple interface to Excel data | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||
| 13 | |||||||||||||
| 14 | my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls'); | ||||||||||||
| 15 | foreach my $sheet ($xls->sheets) { | ||||||||||||
| 16 | while ($sheet->has_data) { | ||||||||||||
| 17 | my @data = $sheet->next_row; | ||||||||||||
| 18 | } | ||||||||||||
| 19 | } | ||||||||||||
| 20 | |||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||
| 22 | |||||||||||||
| 23 | This provides an abstraction to the Spreadsheet::ParseExcel module for | ||||||||||||
| 24 | simple reading of values. | ||||||||||||
| 25 | |||||||||||||
| 26 | You simply loop over the sheets, and fetch rows to arrays. | ||||||||||||
| 27 | |||||||||||||
| 28 | For anything more complex, you probably want to use | ||||||||||||
| 29 | Spreadsheet::ParseExcel directly. | ||||||||||||
| 30 | |||||||||||||
| 31 | =head1 BOOK METHODS | ||||||||||||
| 32 | |||||||||||||
| 33 | =head2 read | ||||||||||||
| 34 | |||||||||||||
| 35 | my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls'); | ||||||||||||
| 36 | |||||||||||||
| 37 | This opens the spreadsheet specified for you. Returns undef if we cannot | ||||||||||||
| 38 | read the book. | ||||||||||||
| 39 | |||||||||||||
| 40 | =head2 sheets | ||||||||||||
| 41 | |||||||||||||
| 42 | @sheets = $xls->sheets; | ||||||||||||
| 43 | |||||||||||||
| 44 | Each spreadsheet can contain one or more worksheets. This fetches them | ||||||||||||
| 45 | all back. You can then iterate over them, or jump straight to the one | ||||||||||||
| 46 | you wish to play with. | ||||||||||||
| 47 | |||||||||||||
| 48 | =head2 book | ||||||||||||
| 49 | |||||||||||||
| 50 | my $book = $xls->book; | ||||||||||||
| 51 | |||||||||||||
| 52 | The Spreadsheet::ParseExcel object we are working with. You can use this | ||||||||||||
| 53 | if you need to manipulate it in ways that this interface doesn't allow. | ||||||||||||
| 54 | |||||||||||||
| 55 | =head1 SHEET METHODS | ||||||||||||
| 56 | |||||||||||||
| 57 | These methods can be called on each sheet returned from $xls->sheets: | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 has_data | ||||||||||||
| 60 | |||||||||||||
| 61 | if ($sheet->has_data) { ... } | ||||||||||||
| 62 | |||||||||||||
| 63 | This lets us know if there are more rows in this sheet that we haven't | ||||||||||||
| 64 | read yet. This allows us to differentiate between an empty row, and | ||||||||||||
| 65 | the end of the sheet. | ||||||||||||
| 66 | |||||||||||||
| 67 | =head2 next_row | ||||||||||||
| 68 | |||||||||||||
| 69 | my @data = $sheet->next_row; | ||||||||||||
| 70 | |||||||||||||
| 71 | Fetch the next row of data back. | ||||||||||||
| 72 | |||||||||||||
| 73 | =head2 sheet | ||||||||||||
| 74 | |||||||||||||
| 75 | my $obj = $sheet->sheet; | ||||||||||||
| 76 | |||||||||||||
| 77 | The underlying Spreadsheet::ParseExcel object for the worksheet. You can | ||||||||||||
| 78 | use this if you need to manipulate it in ways that this interface | ||||||||||||
| 79 | doesn't allow (e.g. asking it for the sheet's name). | ||||||||||||
| 80 | |||||||||||||
| 81 | =head1 AUTHOR | ||||||||||||
| 82 | |||||||||||||
| 83 | Tony Bowden | ||||||||||||
| 84 | |||||||||||||
| 85 | =head1 BUGS and QUERIES | ||||||||||||
| 86 | |||||||||||||
| 87 | Please direct all correspondence regarding this module to: | ||||||||||||
| 88 | bug-Spreadsheet-ParseExcel-Simple@rt.cpan.org | ||||||||||||
| 89 | |||||||||||||
| 90 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 91 | |||||||||||||
| 92 | Copyright (C) 2001-2005 Tony Bowden. | ||||||||||||
| 93 | |||||||||||||
| 94 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||
| 95 | the terms of the GNU General Public License; either version 2 of the License, | ||||||||||||
| 96 | or (at your option) any later version. | ||||||||||||
| 97 | |||||||||||||
| 98 | This program is distributed in the hope that it will be useful, but WITHOUT | ||||||||||||
| 99 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||||||||||
| 100 | FOR A PARTICULAR PURPOSE. | ||||||||||||
| 101 | |||||||||||||
| 102 | =head1 SEE ALSO | ||||||||||||
| 103 | |||||||||||||
| 104 | L<Spreadsheet::ParseExcel>. | ||||||||||||
| 105 | |||||||||||||
| 106 | =cut | ||||||||||||
| 107 | |||||||||||||
| 108 | 0 | ▶ | sub read { | ||||||||||
|
Subroutine
read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 109 | 0 | my $class = shift; | |||||||||||
| 110 | 0 | ▶ | my $book = Spreadsheet::ParseExcel->new->Parse(shift) or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | 0 | bless { book => $book }, $class; | |||||||||||
| 112 | } | ||||||||||||
| 113 | |||||||||||||
| 114 | 0 | ▶ | sub book { shift->{book} } | ||||||||||
|
Subroutine
book: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 115 | |||||||||||||
| 116 | 0 | ▶ | sub sheets { | ||||||||||
|
Subroutine
sheets: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 117 | map Spreadsheet::ParseExcel::Simple::_Sheet->new($_), | ||||||||||||
| 118 | 0 | @{shift->{book}->{Worksheet}}; | |||||||||||
| 119 | } | ||||||||||||
| 120 | |||||||||||||
| 121 | package Spreadsheet::ParseExcel::Simple::_Sheet; | ||||||||||||
| 122 | |||||||||||||
| 123 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||
| 124 | 0 | my $class = shift; | |||||||||||
| 125 | 0 | my $sheet = shift; | |||||||||||
| 126 | bless { | ||||||||||||
| 127 | sheet => $sheet, | ||||||||||||
| 128 | 0 | ▶ | row => $sheet->{MinRow} || 0, | ||||||||||
|
Condition0%0/2
$sheet->{'MinRow'} || 0
MC/DC0%0/1
$sheet->{'MinRow'} || 0
$sheet->{'MinRow'}
Truth table0%0/2
A
A= $sheet->{'MinRow'}
| |||||||||||||
| 129 | }, $class; | ||||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | 0 | ▶ | sub sheet { shift->{sheet} } | ||||||||||
|
Subroutine
sheet: not called CC=1 SCAR=6.9
| |||||||||||||
| 133 | |||||||||||||
| 134 | 0 | ▶ | sub has_data { | ||||||||||
|
Subroutine
has_data: not called CC=2 SCAR=17.9
| |||||||||||||
| 135 | 0 | my $self = shift; | |||||||||||
| 136 | 0 | ▶ | defined $self->{sheet}->{MaxRow} and ($self->{row} <= $self->{sheet}->{MaxRow}); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 137 | } | ||||||||||||
| 138 | |||||||||||||
| 139 | 0 | ▶ | sub next_row { | ||||||||||
|
Subroutine
next_row: not called CC=2 SCAR=17.9
| |||||||||||||
| 140 | 0 | ▶ | map { $_ ? $_->Value : "" } @{$_[0]->{sheet}->{Cells}[$_[0]->{row}++]}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 141 | } | ||||||||||||
| 142 | |||||||||||||
| 143 | 3 | 1; | |||||||||||
| 144 | |||||||||||||