Excel-Grinder

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

# NAME

Excel::Grinder - Import/export plain Excel (XLSX) files as simply as possible.

# DESCRIPTION / PURPOSE

This module should help you read/write XLSX spreadsheets to/from Perl arrays 
as simply as possible. The use cases are (1) when you need to export data from 
your database/application for non-programmers to enjoy in their beloved Excel 
and (2) when you need to allow for batch import/update operations via 
user-provided Excel.

There are so many awesome things you can do with Excel (formatting, formulas, 
pivot tables, etc.) but this module does none of that.  This is for the basic 
read-it-in and write-it-out -- which might just fit the bill.

This module will read an Excel (XLSX) file into a three-level arrayref.  The first
level is the worksheets, second level is the rows, and third level is the cells, such that:

        $$my_data[4][2][10] --> Worksheet 5, Row 3, Column 11 (aka as Column K)
        

Form a three-level arrayref to represent worksheets/rows/cells in this way, and you can create
a plain Excel XLSX file.  No formatting or formulas.  Ready for Tableau or just to confuse
your favorite front-line manager.

I put this together because I was offended at how difficult it is just to create an Excel
file in certain non-Perl environments, and since Excel is just a part of life for so many of us,
it really should be dead-simple.

To pursue additional Excel features, please see the excellent [Excel::Writer::XLSX](https://metacpan.org/pod/Excel%3A%3AWriter%3A%3AXLSX) and 
[Spreadsheet::XLSX](https://metacpan.org/pod/Spreadsheet%3A%3AXLSX) modules, of which this module is just a simple abstraction.

# SYNOPSIS

        # create the object to read/write excel files
        my $xlsx = Excel::Grinder->new('/opt/data/excel_files'); 
        # the directory can be anywhere that is writable; leave blank for /tmp/excel_grinder

        # to create a two-worksheet Excel workbook at /opt/data/excel_files/our_family.xlsx
        my $full_file_path = $xlsx->write_excel(
                'filename' => 'our_family.xlsx',
                'headings_in_data' => 1,
                'worksheet_names' => ['Dogs','People'],
                'the_data' => [
                        [
                                ['Name','Main Trait','Age Type'],
                                ['Ginger','Wonderful','Old'],
                                ['Pepper','Loving','Passed'],
                                ['Polly','Fun','Young'],
                                ['Daisy','Crazy','Puppy']
                        ],
                        [
                                ['Name','Main Trait','Age Type'],
                                ['Melanie','Smart','Oldish'],
                                ['Lorelei','Fun','Young'],
                                ['Eric','Fat','Old']
                        ]
                ],
        );      
        
        # if you prebuilt had that three-level array in $our_family_data:
        $full_file_path = $xlsx->write_excel(
                'filename' => 'our_family.xlsx',
                'headings_in_data' => 1,
                'worksheet_names' => ['Dogs','People'], 
                'the_data' => $our_family_data
        );
        
        # to read that spreadsheet back into an three-level arrayref that is just like
        # what we fed in to write_excel() above:        
        my $family_data = $xlsx->read_excel('our_family.xlsx');

        # Now you can modify or add to $family_data, and overwrite our_family.xlsx 
        # or create another XLSX file.

# METHODS

## new()

Creates a new object to use this module.  Accepts a 'default directory' path for where
to save / load the Excel files:

        $xlsx = Excel::Grinder->new('/home/ginger/excel_files');



( run in 0.925 second using v1.01-cache-2.11-cpan-5837b0d9d2c )