/[webpac2]/trunk/lib/WebPAC/Input/Excel.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/WebPAC/Input/Excel.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 728 by dpavlin, Fri Sep 29 19:52:26 2006 UTC revision 1217 by dpavlin, Tue Jun 9 18:38:36 2009 UTC
# Line 9  use base qw/WebPAC::Common/; Line 9  use base qw/WebPAC::Common/;
9    
10  =head1 NAME  =head1 NAME
11    
12  WebPAC::Input::Excel - support for Microsoft Excell and compatibile files  WebPAC::Input::Excel - support for Microsoft Excel and compatibile files
   
 =head1 VERSION  
   
 Version 0.04  
13    
14  =cut  =cut
15    
16  our $VERSION = '0.04';  our $VERSION = '0.05';
17    
18    
19  =head1 SYNOPSIS  =head1 SYNOPSIS
# Line 39  Returns handle to database and size Line 35  Returns handle to database and size
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    
# Line 57  sub new { Line 54  sub new {
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} };
# Line 68  sub new { Line 65  sub new {
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};
# Line 96  Return record with ID C<$mfn> from datab Line 91  Return record with ID C<$mfn> from datab
91    
92    my $rec = $self->fetch_rec( $mfn );    my $rec = $self->fetch_rec( $mfn );
93    
94  }  Columns are named C<A>, C<B> and so on...
95    
96  =cut  =cut
97    
# Line 118  sub fetch_rec { Line 113  sub fetch_rec {
113          $log->debug("fetch_rec( $mfn ) row: $row cols: ",$sheet->{MinCol}," - ",$sheet->{MaxCol});          $log->debug("fetch_rec( $mfn ) row: $row cols: ",$sheet->{MinCol}," - ",$sheet->{MaxCol});
114    
115          foreach my $col ( $sheet->{MinCol} ... $sheet->{MaxCol} ) {          foreach my $col ( $sheet->{MinCol} ... $sheet->{MaxCol} ) {
116                  if (my $v = $sheet->{Cells}->[$row]->[$col]->{Val}) {                  if (my $v = $sheet->{Cells}->[$row]->[$col]->{_Value}) {        ## XXX _Value = formatted | Val = unformated !
117                          $rec->{ int2col($col) } = $v;                          $rec->{ int2col($col) } = $v;
118                  }                  }
119          }          }
# Line 141  sub size { Line 136  sub size {
136          my $self = shift;          my $self = shift;
137          return $self->{size};          return $self->{size};
138  }  }
139    
140    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> >>

Legend:
Removed from v.728  
changed lines
  Added in v.1217

  ViewVC Help
Powered by ViewVC 1.1.26