11 |
|
|
12 |
WebPAC::Input::Excel - support for Microsoft Excel and compatibile files |
WebPAC::Input::Excel - support for Microsoft Excel and compatibile files |
13 |
|
|
|
=head1 VERSION |
|
|
|
|
|
Version 0.04 |
|
|
|
|
14 |
=cut |
=cut |
15 |
|
|
16 |
our $VERSION = '0.04'; |
our $VERSION = '0.05'; |
17 |
|
|
18 |
|
|
19 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
35 |
} |
} |
36 |
|
|
37 |
C<worksheet> is case and white-space insensitive name of worksheet in Excel |
C<worksheet> is case and white-space insensitive name of worksheet in Excel |
38 |
file to use. If not specified, it will use first worksheet in file. |
file to use. If not specified, name of input is used. If none of those |
39 |
|
methods returned sheet, first worksheet in file is used instead. |
40 |
|
|
41 |
C<from> and C<to> specify row numbers to start and finish import. |
C<from> and C<to> specify row numbers to start and finish import. |
42 |
|
|
54 |
my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($self->{path}); |
my $workbook = Spreadsheet::ParseExcel::Workbook->Parse($self->{path}); |
55 |
|
|
56 |
my $sheet; |
my $sheet; |
57 |
my $wanted_worksheet; |
my $wanted_worksheet = $self->{worksheet} || $self->{name}; |
58 |
|
|
59 |
if ($wanted_worksheet = $self->{worksheet}) { |
if ($wanted_worksheet) { |
60 |
my $name; |
my $name; |
61 |
do { |
do { |
62 |
$sheet = shift @{ $workbook->{Worksheet} }; |
$sheet = shift @{ $workbook->{Worksheet} }; |
65 |
$name =~ s/\s\s+/ /g; |
$name =~ s/\s\s+/ /g; |
66 |
} until ($name =~ m/^\s*\Q$wanted_worksheet\E\s*$/i); |
} until ($name =~ m/^\s*\Q$wanted_worksheet\E\s*$/i); |
67 |
|
|
|
} else { |
|
|
|
|
|
$sheet = shift @{ $workbook->{Worksheet} }; |
|
|
|
|
68 |
} |
} |
69 |
|
|
70 |
|
$sheet ||= shift @{ $workbook->{Worksheet} }; |
71 |
|
|
72 |
$self->{sheet} = $sheet; |
$self->{sheet} = $sheet; |
73 |
|
|
74 |
$self->{from} ||= $sheet->{MinRow}; |
$self->{from} ||= $sheet->{MinRow}; |
139 |
|
|
140 |
sub default_encoding { 'UTF-16' } |
sub default_encoding { 'UTF-16' } |
141 |
|
|
142 |
|
our @labels; |
143 |
|
our @names; |
144 |
|
|
145 |
|
sub normalize { |
146 |
|
my ($self,$mfn) = @_; |
147 |
|
|
148 |
|
my $log = $self->_get_logger(); |
149 |
|
|
150 |
|
my $sheet = $self->{sheet}; |
151 |
|
|
152 |
|
if ( ! @labels ) { |
153 |
|
push @labels, $sheet->{Cells}->[0]->[$_]->{_Value} |
154 |
|
foreach ( $sheet->{MinCol} ... $sheet->{MaxCol} ) |
155 |
|
; |
156 |
|
@names = map { s{\W+}{_}; $_ } @labels; |
157 |
|
$log->loginfo("column labels:", @labels, @names); |
158 |
|
} |
159 |
|
|
160 |
|
my $row = $self->{from} + $mfn - 1; |
161 |
|
|
162 |
|
|
163 |
|
} |
164 |
|
|
165 |
=head1 AUTHOR |
=head1 AUTHOR |
166 |
|
|
167 |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |
Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >> |