Rafael Kitover
and 1 contributors


Catalyst::Action::Serialize::SimpleExcel - Serialize to Excel files


Serializes tabular data to an Excel file. Not terribly configurable, but should suffice for simple purposes.

In your REST Controller:

    package MyApp::Controller::REST;

    use parent 'Catalyst::Controller::REST';
    use DBIx::Class::ResultClass::HashRefInflator ();
    use POSIX 'strftime';

    __PACKAGE__->config->{map}{'application/vnd.ms-excel'} = 'SimpleExcel';

    sub books : Local ActionClass('REST') {}

    sub books_GET {
        my ($self, $c) = @_;

        my $books_rs = $c->model('MyDB::Book')->search({}, {
            order_by => 'author,title'


        my @books = map {
            [ @{$_}{qw/author title/} ]
        } $books_rs->all;

        my $authors_rs = $c->model('MyDB::Author')->search({}, {
            order_by => 'last_name,middle_name,last_name'


        my @authors = map {
            [ @{$_}{qw/first_name middle_name last_name/} ]
        } $authors_rs->all;

        my $entity = {
            sheets => [
                    name => 'Books',
                    header => ['Author', 'Title'], # will be bold
                    rows => \@books,
                    name => 'Authors',
                    header => ['First Name', 'Middle Name', 'Last Name'],
                    rows => \@authors,
            # the part before .xls, which is automatically appended
            filename => 'myapp-books-'.strftime('%m-%d-%Y', localtime)

            entity => $entity

In your javascript, to initiate a file download:

    // this uses jQuery
    function export_to_excel() {
        $('<iframe '

Note, the content-type query param is required if you're just linking to the action. It tells Catalyst::Controller::REST what you're serializing the data as.


Your entity should be either an array of arrays, an array of arrays of arrays, or a hash with the keys as described below and in the "SYNOPSIS".

If entity is a hashref, keys should be:


An array of worksheets. Either sheets or a worksheet specification at the top level is required.


Optional. The name of the file before .xls. Defaults to "data".

Each sheet should be an array of arrays, or a hashref with the following fields:


Optional. The name of the worksheet.


Required. The array of arrays of rows.

Optional, an array for the first line of the sheet, which will be in bold.


Optional, the widths in characters of the columns. Otherwise the widths are calculated automatically from the data and header.

If you only have one sheet, you can put it in the top level hash.


Rafael Kitover, <rkitover at cpan.org>


Please report any bugs or feature requests to bug-catalyst-action-serialize-simpleexcel at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Action-Serialize-SimpleExcel. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


Catalyst, Catalyst::Controller::REST, Catalyst::Action::REST, Catalyst::View::Excel::Template::Plus, Spreadsheet::WriteExcel, Spreadsheet::ParseExcel


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

    perldoc Catalyst::Action::Serialize::SimpleExcel

You can also look for information at:


Copyright (c) 2008-2011 Rafael Kitover

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