Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

  (email not shown publicly)

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Friday December 20, 2002
10:14 AM

Writing a program to mail an Excel file as an attachment

[ #9572 ]

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 => '',
              To => '',
              Subject => 'Example: mailing an Excel workbook',
              Type => 'TEXT',
              Data => <<'EOF',
Here is your example Excel workbook.
         Type => 'application/',
         Data => $xls->data,
         Filename => 'example.xls',

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Yes, I wrote a very simple MIME-Lite script that mails files to people as attachments. It's so much simpler than fiddling around in my mailer, and I can pipe to it. (MIME-Lite)++