13 |
|
|
14 |
=head1 VERSION |
=head1 VERSION |
15 |
|
|
16 |
Version 0.01 |
Version 0.02 |
17 |
|
|
18 |
=cut |
=cut |
19 |
|
|
20 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
21 |
|
|
22 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
37 |
my ($db,$size) = $open_db( |
my ($db,$size) = $open_db( |
38 |
path => '/path/to/workbook.xls' |
path => '/path/to/workbook.xls' |
39 |
worksheet => 'name of sheet', |
worksheet => 'name of sheet', |
40 |
|
from => 42, |
41 |
|
to => 9999, |
42 |
} |
} |
43 |
|
|
44 |
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 |
45 |
file to use. If not specified, it will use first worksheet in file. |
file to use. If not specified, it will use first worksheet in file. |
46 |
|
|
47 |
|
C<from> and C<to> specify row numbers to start and finish import. |
48 |
|
|
49 |
=cut |
=cut |
50 |
|
|
51 |
my $sheet; |
my $sheet; |
52 |
|
my ($from,$to); |
53 |
|
|
54 |
sub open_db { |
sub open_db { |
55 |
my $self = shift; |
my $self = shift; |
68 |
my $name; |
my $name; |
69 |
do { |
do { |
70 |
$sheet = shift @{ $workbook->{Worksheet} }; |
$sheet = shift @{ $workbook->{Worksheet} }; |
71 |
|
$log->logdie("can't find sheet '$wanted_worksheet' in $arg->{path}\n") unless (defined($sheet)); |
72 |
$name = $sheet->{Name}; |
$name = $sheet->{Name}; |
73 |
$name =~ s/\s\s+/ /g; |
$name =~ s/\s\s+/ /g; |
74 |
} until ($name =~ m/^\s*\Q$wanted_worksheet\E\s*$/i); |
} until ($name =~ m/^\s*\Q$wanted_worksheet\E\s*$/i); |
79 |
|
|
80 |
} |
} |
81 |
|
|
82 |
$size = $sheet->{MaxRow} - $sheet->{MinRow}; |
$from = $arg->{from} || $sheet->{MinRow}; |
83 |
|
$to = $arg->{to} || $sheet->{MaxRow}; |
84 |
|
|
85 |
|
$size = $to - $from; |
86 |
|
|
87 |
$log->warn("opening Excel file '$arg->{path}', using ", |
$log->warn("opening Excel file '$arg->{path}', using ", |
88 |
$wanted_worksheet ? '' : 'first ', |
$wanted_worksheet ? '' : 'first ', |
114 |
|
|
115 |
my $rec; |
my $rec; |
116 |
|
|
117 |
my $row = $sheet->{MinRow} + $mfn - 1; |
my $row = $from + $mfn - 1; |
118 |
|
|
119 |
$log->debug("fetch_rec( $mfn ) row: $row cols: ",$sheet->{MinCol}," - ",$sheet->{MaxCol}); |
$log->debug("fetch_rec( $mfn ) row: $row cols: ",$sheet->{MinCol}," - ",$sheet->{MaxCol}); |
120 |
|
|