Mailing List Archive

RFC: Catalyst::Action::Serialize::SimpleExcel
svn:
http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Action-Serialize-SimpleExcel/1.000/trunk/

dev release on CPAN
R/RK/RKITOVER/Catalyst-Action-Serialize-SimpleExcel-0.01_01.tar.gz

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

VERSION
Version 0.01_01

SYNOPSIS
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 POSIX 'strftime';

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

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

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

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

my @t = map {
my $row = $_;
[ map $row->$_, qw/author title/ ]
} $rs->all;

my $entity = {
header => ['Author', 'Title'], # will be bold
column_widths => [30, 50], # in characters
rows => \@t,
# the part before .xls, which is automatically appended
filename => 'myapp-books-'.strftime('%m-%d-%Y', localtime)
};

$self->status_ok(
$c,
entity => $entity
);
}

In your javascript, to initiate a file download:

// this uses jQuery
function export_to_excel() {
$('<iframe '
+'src="/rest/books?content-type=application%2Fvnd.ms-excel">')
.hide().appendTo('body');
}

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

DESCRIPTION
Your entity should be either an array of arrays, or the more embellished
format described in the "SYNOPSIS".

AUTHOR
Rafael Kitover, "<rkitover at cpan.org>"

BUGS
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-Serializ
e-SimpleExcel>. I will be notified, and then you'll automatically be
notified of progress on your bug as I make changes.

TODO
* Split into mutliple overridable methods.

* Multiple sheet support.

* Autofit support (would require a macro.)

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

perldoc Catalyst::Action::Serialize::SimpleExcel

You can also look for information at:

* RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Action-Serialize-

* AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Catalyst-Action-Serialize-SimpleExcel>

* CPAN Ratings

<http://cpanratings.perl.org/d/Catalyst-Action-Serialize-SimpleExcel
>

* Search CPAN

<http://search.cpan.org/dist/Catalyst-Action-Serialize-SimpleExcel/>

COPYRIGHT & LICENSE
Copyright (c) 2008 Rafael Kitover

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


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: RFC: Catalyst::Action::Serialize::SimpleExcel [ In reply to ]
On Tue, Nov 11, 2008 at 4:17 AM, Rafael Kitover <rkitover@io.com> wrote:
> svn:
> http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-Action-Serialize-SimpleExcel/1.000/trunk/
>
> dev release on CPAN
> R/RK/RKITOVER/Catalyst-Action-Serialize-SimpleExcel-0.01_01.tar.gz
>
> NAME
> Catalyst::Action::Serialize::SimpleExcel - Serialize tables to Excel
> files
>
> VERSION
> Version 0.01_01
>
> SYNOPSIS
> 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 POSIX 'strftime';
>
> __PACKAGE__->config->{map}{'application/vnd.ms-excel'} =
> 'SimpleExcel';
>
> sub books : Local ActionClass('REST') {}
>
> sub books_GET {
> my ($self, $c) = @_;
>
> my $rs = $c->model('MyDB::Book')->search({}, {
> order_by => 'author,title'
> });
>
> my @t = map {
> my $row = $_;
> [ map $row->$_, qw/author title/ ]
> } $rs->all;
>
> my $entity = {
> header => ['Author', 'Title'], # will be bold
> column_widths => [30, 50], # in characters
> rows => \@t,
> # the part before .xls, which is automatically appended
> filename => 'myapp-books-'.strftime('%m-%d-%Y', localtime)
> };
>
> $self->status_ok(
> $c,
> entity => $entity
> );
> }
>
> In your javascript, to initiate a file download:
>
> // this uses jQuery
> function export_to_excel() {
> $('<iframe '
> +'src="/rest/books?content-type=application%2Fvnd.ms-excel">')
> .hide().appendTo('body');
> }
>
> Note, the content-type query param is required if you're just linking to
> the action. It tells C::C::REST what you're serializing the data as.
>
> DESCRIPTION
> Your entity should be either an array of arrays, or the more embellished
> format described in the "SYNOPSIS".
>
> AUTHOR
> Rafael Kitover, "<rkitover at cpan.org>"
>
> BUGS
> 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-Serializ
> e-SimpleExcel>. I will be notified, and then you'll automatically be
> notified of progress on your bug as I make changes.
>
> TODO
> * Split into mutliple overridable methods.
>
> * Multiple sheet support.
>
> * Autofit support (would require a macro.)
>
> SUPPORT
> You can find documentation for this module with the perldoc command.
>
> perldoc Catalyst::Action::Serialize::SimpleExcel
>
> You can also look for information at:
>
> * RT: CPAN's request tracker
>
> <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Action-Serialize-
> SimpleExcel>
>
> * AnnoCPAN: Annotated CPAN documentation
>
> <http://annocpan.org/dist/Catalyst-Action-Serialize-SimpleExcel>
>
> * CPAN Ratings
>
> <http://cpanratings.perl.org/d/Catalyst-Action-Serialize-SimpleExcel
> >
>
> * Search CPAN
>
> <http://search.cpan.org/dist/Catalyst-Action-Serialize-SimpleExcel/>
>
> COPYRIGHT & LICENSE
> Copyright (c) 2008 Rafael Kitover
>
> This program is free software; you can redistribute it and/or modify it
> under the same terms as Perl itself.
>
>


Hi Rafael,

Good work, this looks like a very useful module. I look forward to
seeing it on CPAN.

One thing you may want to do in the examples is to use the
HashRefInflator instead of simply mapping (just for efficiency).

http://search.cpan.org/~ash/DBIx-Class-0.08010/lib/DBIx/Class/ResultClass/HashRefInflator.pm

Thanks,
-J

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev