Excel-ValueReader-XLSX

 view release on metacpan or  search on metacpan

lib/Excel/ValueReader/XLSX.pm  view on Meta::CPAN

  # iterator version of ->table()
  my ($columns, $iterator) = $reader->itable($table_name);
  while (my $record = $iterator->()) { process_record($record) }

=head1 DESCRIPTION

=head2 Purpose

This module reads the contents of an Excel file in XLSX format.
Unlike other modules like L<Spreadsheet::ParseXLSX> or L<Data::XLSX::Parser>, 
this module has no support for reading formulas, formats or other Excel internal
information; all you get are plain values -- but you get them much faster ! 

Besides, this API has some features not found in concurrent parsers :

=over

=item *

has support for parsing Excel tables

lib/Excel/ValueReader/XLSX/Backend/LibXML.pm  view on Meta::CPAN

        if ($col_A1) {$col_num = $Excel::ValueReader::XLSX::A1_to_num_memoized{$col_A1}
                             //= Excel::ValueReader::XLSX->A1_to_num($col_A1)}
        else         {$col_num++}

        $cell_type  = $xml_reader->getAttribute('t');
        $cell_style = $xml_reader->getAttribute('s');
        $seen_node  = '';
      }

      elsif ($node_name =~ /^[vtf]$/) {
        # remember that we have seen a 'value' or 'text' or 'formula' node
        $seen_node = $node_name;
      }

      elsif ($node_name eq '#text') {
        #start processing cell content

        my $val = $xml_reader->value;
        $cell_type //= '';

        if ($seen_node eq 'v')  {

lib/Excel/ValueReader/XLSX/Backend/LibXML.pm  view on Meta::CPAN

              $val = $self->strings->[$val]; # string -- pointer into the global array of shared strings
            }
            else {
              warn "unexpected non-numerical value: $val inside a node of shape <v t='s'>\n";
            }
          }
          elsif ($cell_type eq 'e') {
            $val = undef; # error -- silently replace by undef
          }
          elsif ($cell_type =~ /^(n|d|b|str|)$/) {
            # number, date, boolean, formula string or no type : content is already in $val

          # if this is a date, replace the numeric value by the formatted date
            if ($has_date_formatter && $cell_style && looks_like_number($val) && $val >= 0) {
              my $date_style = $self->date_styles->[$cell_style];
              $val = $self->formatted_date($val, $date_style)    if $date_style;
            }
          }
          else {
            # handle unexpected cases
            warn "unsupported type '$cell_type' in cell L${row_num}C${col_num}\n";

lib/Excel/ValueReader/XLSX/Backend/LibXML.pm  view on Meta::CPAN

          $rows[-1][$col_num-1] = $val;
        }

        elsif ($seen_node eq 't' && $cell_type eq 'inlineStr')  {
          # inline string -- accumulate all #text nodes until next cell
          no warnings 'uninitialized';
          $rows[-1][$col_num-1] .= $val;
        }

        elsif ($seen_node eq 'f')  {
          # formula -- just ignore it
        }

        else {
          # handle unexpected cases
          warn "unexpected text node in cell L${row_num}C${col_num}: $val\n";
        }
      }
    }

    # end of XML nodes. In iterator mode, return a row if we have one



( run in 0.513 second using v1.01-cache-2.11-cpan-26ccb49234f )