Mojolicious::Plugin::WriteExcel - write Excel spreadsheets from Mojolicious
# Mojolicious $self->plugin('write_excel'); # Mojolicious::Lite plugin 'write_excel'; # Render a spreadsheet get '/example.xls' => sub { shift->render( handler => 'xls', result => [[qw(foo bar baz)], [qw(lol wut bbq)], [qw(kick ass module)],], ); };
Mojolicious::Plugin::WriteExcel is a plugin for writing Excel spreadsheets.
This plugin converts the result element in the stash to an Excel spreadsheet. If the stash also has a heading element, the renderer will also write headings in bold type for the columns in the spreadsheet.
result
heading
heading is an arrayref, while result is an array of arrayrefs.
Optionally, a settings parameter can be provided to set additional attributes in the Excel spreadsheet. Currently 'column_width' is the only working attribute. settings is a hashref. Column widths could be set by passing the settings to render:
settings
render
get '/colwidth.xls' => sub { shift->render( handler => 'xls', result => [['small'], ['medium'], ['large']], settings => {column_width => {'A:A' => 10, 'B:B' => 25, 'C:D' => 40}}, ); }; settings => {column_width => {'A:A' => 10, 'B:B' => 25, 'C:D' => 40}}
Mojolicious::Plugin::WriteExcel inherits all methods from Mojolicious::Plugin and implements the following new ones.
xls_renderer
$app->renderer->add_handler(xls => \&xls_renderer);
Internal sub talking to Spreadsheet::WriteExcel::Simple to render spreadsheets.
register
$plugin->register;
Register renderer in Mojolicious application.
Zak B. Elep <zakame@cpan.org>
Thanks to Graham Barr and his MojoX::Renderer::YAML module, and Sebastian Riedel's core Mojolicious::Plugin::EpRenderer for showing how to write renderers for Mojolicious!
Inspiration for this renderer came from this mailing list thread: http://www.mail-archive.com/plug@lists.linux.org.ph/msg21881.html
Copyright 2013 Zak B. Elep
This library is free software; yu can redistribute it and/or modify it under the same terms as Perl itself.
Mojolicious, Spreadsheet::WriteExcel::Simple, http://mojolicious.org.
To install Mojolicious::Plugin::WriteExcel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::WriteExcel
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::WriteExcel
For more information on module installation, please visit the detailed CPAN module installation guide.