added from and to parametars for start and end row to import
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 21 May 2006 19:38:56 +0000 (19:38 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 21 May 2006 19:38:56 +0000 (19:38 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@524 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Input/Excel.pm

index c2be75a..c05f38d 100644 (file)
@@ -13,11 +13,11 @@ WebPAC::Input::Excel - support for Microsoft Excell and compatibile files
 
 =head1 VERSION
 
-Version 0.01
+Version 0.02
 
 =cut
 
-our $VERSION = '0.01';
+our $VERSION = '0.02';
 
 
 =head1 SYNOPSIS
@@ -37,14 +37,19 @@ Returns handle to database and size
   my ($db,$size) = $open_db(
        path => '/path/to/workbook.xls'
        worksheet => 'name of sheet',
+       from => 42,
+       to => 9999,
   }
 
 C<worksheet> is case and white-space insensitive name of worksheet in Excel
 file to use. If not specified, it will use first worksheet in file.
 
+C<from> and C<to> specify row numbers to start and finish import.
+
 =cut
 
 my $sheet;
+my ($from,$to);
 
 sub open_db {
        my $self = shift;
@@ -63,6 +68,7 @@ sub open_db {
                my $name;
                do {
                        $sheet = shift @{ $workbook->{Worksheet} };
+                       $log->logdie("can't find sheet '$wanted_worksheet' in $arg->{path}\n") unless (defined($sheet));
                        $name = $sheet->{Name};
                        $name =~ s/\s\s+/ /g;
                } until ($name =~ m/^\s*\Q$wanted_worksheet\E\s*$/i);
@@ -73,7 +79,10 @@ sub open_db {
        
        }
 
-       $size = $sheet->{MaxRow} - $sheet->{MinRow};
+       $from = $arg->{from} || $sheet->{MinRow};
+       $to = $arg->{to} || $sheet->{MaxRow};
+
+       $size = $to - $from;
 
        $log->warn("opening Excel file '$arg->{path}', using ",
                $wanted_worksheet ? '' : 'first ',
@@ -105,7 +114,7 @@ sub fetch_rec {
 
        my $rec;
 
-       my $row = $sheet->{MinRow} + $mfn - 1;
+       my $row = $from + $mfn - 1;
 
        $log->debug("fetch_rec( $mfn ) row: $row cols: ",$sheet->{MinCol}," - ",$sheet->{MaxCol});