Sometimes modules just come together in such a way as to make my life very easy and enable me to dazzle the people I work for. In this case, simplified APIs to more complicated functionality: MIME::Lite and Spreadsheet::WriteExcel::Simple. Here's an example of how to create and mail a simple spreadsheet as an attachment. For bonus points, generalize it to get the data from DBI or a Data::Table object.
#!/usr/local/bin/perl5.8.0 -- # -*- perl -*- use warnings; use strict; use Spreadsheet::WriteExcel::Simple; use MIME::Lite; my $xls = Spreadsheet::WriteExcel::Simple->new; $xls->write_bold_row([qw(col1 col2 col3)]); for (1 .. 5) { $xls->write_row([qw(one two three)]); } my $msg = MIME::Lite->new( From => 'me@example.com', To => 'you@example.com', Subject => 'Example: mailing an Excel workbook', Type => 'TEXT', Data => <<'EOF', Here is your example Excel workbook. EOF ); $msg->attach( Type => 'application/vnd.ms-excel', Data => $xls->data, Filename => 'example.xls', ); $msg->send;
--Nat