Spreadsheet::ParseExcel::Simple - A simple interface to Excel data


Spreadsheet-ParseExcel-Simple documentation Contained in the Spreadsheet-ParseExcel-Simple distribution.

Index


Code Index:

NAME

Top

Spreadsheet::ParseExcel::Simple - A simple interface to Excel data

SYNOPSIS

Top

  my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls');
  foreach my $sheet ($xls->sheets) {
     while ($sheet->has_data) {  
         my @data = $sheet->next_row;
     }
  }

DESCRIPTION

Top

This provides an abstraction to the Spreadsheet::ParseExcel module for simple reading of values.

You simply loop over the sheets, and fetch rows to arrays.

For anything more complex, you probably want to use Spreadsheet::ParseExcel directly.

BOOK METHODS

Top

read

  my $xls = Spreadsheet::ParseExcel::Simple->read('spreadsheet.xls');

This opens the spreadsheet specified for you. Returns undef if we cannot read the book.

sheets

  @sheets = $xls->sheets;

Each spreadsheet can contain one or more worksheets. This fetches them all back. You can then iterate over them, or jump straight to the one you wish to play with.

book

	my $book = $xls->book;

The Spreadsheet::ParseExcel object we are working with. You can use this if you need to manipulate it in ways that this interface doesn't allow.

SHEET METHODS

Top

These methods can be called on each sheet returned from $xls->sheets:

has_data

  if ($sheet->has_data) { ... }

This lets us know if there are more rows in this sheet that we haven't read yet. This allows us to differentiate between an empty row, and the end of the sheet.

next_row

  my @data = $sheet->next_row;

Fetch the next row of data back.

sheet

	my $obj = $sheet->sheet;

The underlying Spreadsheet::ParseExcel object for the worksheet. You can use this if you need to manipulate it in ways that this interface doesn't allow (e.g. asking it for the sheet's name).

AUTHOR

Top

Tony Bowden

BUGS and QUERIES

Top

Please direct all correspondence regarding this module to: bug-Spreadsheet-ParseExcel-Simple@rt.cpan.org

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

Spreadsheet::ParseExcel.


Spreadsheet-ParseExcel-Simple documentation Contained in the Spreadsheet-ParseExcel-Simple distribution.

package Spreadsheet::ParseExcel::Simple;

$VERSION = '1.04';

use strict;
use Spreadsheet::ParseExcel;

sub read {
  my $class = shift;
  my $book = Spreadsheet::ParseExcel->new->Parse(shift) or return;
  bless { book => $book }, $class;
}

sub book { shift->{book} }

sub sheets {
  map Spreadsheet::ParseExcel::Simple::_Sheet->new($_), 
   @{shift->{book}->{Worksheet}};
}

package Spreadsheet::ParseExcel::Simple::_Sheet;

sub new {
  my $class = shift;
  my $sheet = shift;
  bless {
    sheet => $sheet,
    row   => $sheet->{MinRow} || 0,
  }, $class;
}

sub sheet { shift->{sheet} }

sub has_data { 
  my $self = shift;
  defined $self->{sheet}->{MaxRow} and ($self->{row} <= $self->{sheet}->{MaxRow});
}

sub next_row {
  map { $_ ? $_->Value : "" } @{$_[0]->{sheet}->{Cells}[$_[0]->{row}++]};
}

1;