Zoffix Znet > Spreadsheet-DataFromExcel > Spreadsheet::DataFromExcel

Download:
Spreadsheet-DataFromExcel-1.001003.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.001003   Source  

NAME ^

Spreadsheet::DataFromExcel - read a sheet from Excel file into a simple arrayref of arrayrefs

SYNOPSIS ^

    use strict;
    use warnings;
    use Spreadsheet::DataFromExcel;

    my $p = Spreadsheet::DataFromExcel->new;

    # Excel file has three columns and five rows
    my $data = $p->load('file.xls')
        or die $p->error;

    use Data::Dumper;
    print Dumper $data;

    # prints:
    $VAR1 = [
          [
            'ID',
            'Time',
            'Number'
          ],
          [
            1,
            '1248871908',
            '0.020068370810808'
          ],
          [
            2,
            '1248871908',
            '0.765251959066035'
          ],
          [
            3,
            '1248871908',
            '0.146082393164885'
          ],
          [
            4,
            undef,
            '0.618001895581024'
          ],
    ]

DESCRIPTION ^

For some lucky reason I often and up given data to work with in Excel format. Nothing fancy, just one sheet with basic string data.

My steps to utilize it in a perl program were either copy/pasting it into a text file and splitting on \t or firing up Spreadsheet::ParseExcel and trying to figure out what exactly that I needed was. No more! Welcome the Spreadsheet::DataFromExcel!

Spreadsheet::DataFromExcel to Spreadsheet::ParseExcel is what a bycicle is to a freight truck. Spreadsheet::DataFromExcel offers a "no crust" loading of Excel sheets into an arrayref of arrayrefs where each inner arrayref represents a row and its elements represent cells.

If you're looking for any more control or data, see Spreadsheet::ParseExcel or Spreadsheet::Read

CONSTRUCTOR ^

new

    my $p = Spreadsheet::DataFromExcel->new;

Takes no arguments, returns a freshly baked Spreadsheet::DataFromExcel object.

METHODS ^

load

    # simple
    my $data = $p->load('file.xls')
        or die $p->error;

    # with all the optionals set
    my $data = $p->load(
        'file.xls',
        'SheetName',
        0,   # start row number; starting counting with 0
        10,  # end row number
    ) or die $p->error;

On success returns an arrayref of arrayrefs where each inner arrayref represents a row in the Excel sheet and each element of those inner arreyrefs is a scalar that contains the data for each cell in that row. If a particular cell is empty, it will be represented with an undef. On error returns either undef or an empty list (depending on the context) and the reason for failure will be available via error() method.

Takes one mandatory and three optional arguments; if you want want to keep an argument at its default, set it to undef. The arguments are as follows:

first argument (the filename)

    my $data = $p->load('file.xls')
        or die $p->error;

Mandatory. Specifies the filename of the Excel file to read. If the file was not found or is not an Excel file, load() will error out.

second argument (sheet name)

    my $data = $p->load(
        'file.xls',
        'SheetName', # sheet name
    ) or die $p->error;

    my $data = $p->load(
        'file.xls',
        1, # sheet number
    ) or die $p->error;

Optional. Takes either a string or a number as a value that specifies the name or sheet number to load. Note: if some sheet's name is a number and it matches the number you pass as the second argumnet (in attempt to load a sheet by number) then that number will be taken as sheet's name and you may end up with the wrong sheet. If the specified sheet was not found, load() will error out. By default load() will load up the first sheet as returned by Spreadsheet::ParseExcel's workbook worksheets() method.

third argumnet (start row number)

    my $data = $p->load(
        'file.xls',
        undef, # leave the second argument at its default
        0,     # start row number; starting counting with 0
    ) or die $p->error;

Optional. Specifies the starting row number from which to start loading of data. Note that counting starts from zero (in Excel it starts from one). By default will start with whatever Spreadsheet::ParseExcel's $worksheet->row_range thinks as the first starting row with data.

fourth argument (end row number)

    my $data = $p->load(
        'file.xls',
        undef, # default sheet
        undef, # default starting row
        10,    # end row number
    ) or die $p->error;

Optional. Specifies the end row number at which to stop loading of data. Note that counting starts from zero (in Excel it starts from one). By default will end with whatever Spreadsheet::ParseExcel's $worksheet->row_range thinks as the last row with data. There's no real harm of specifying too high of end row number; you'll only end up with a bunch of undefs as cell values in those arrayref-rows that went above the limit.

error

    my $data = $p->load('file.xls')
        or die $p->error;

Takes no arguments, returns the reason for why load() failed.

SEE ALSO ^

Spreadsheet::ParseExcel, Spreadsheet::Read

REPOSITORY ^

Fork this module on GitHub: https://github.com/zoffixznet/Spreadsheet-DataFromExcel

AUTHOR ^

Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com, http://haslayout.net)

BUGS ^

Please report any bugs or feature requests on GitHub https://github.com/zoffixznet/Spreadsheet-DataFromExcel/issues or, alternatively and not preferred, RT:

bug-spreadsheet-datafromexcel at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Spreadsheet-DataFromExcel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Spreadsheet::DataFromExcel

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2009 'Zoffix, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: