Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use DBI; use MIME::Lite; use Spreadsheet::WriteExcel; use Data::Dumper; my $ORACLE_HOME = '/u01/app/oracle/product/10.2.0/db_1/'; $ENV{'ORACLE_HOME'} = '/u01/app/oracle/product/10.2.0/db_1'; my $dsn = 'dns goes here'; my $usr = 'uid goes here'; my $pass = 'pass goes here'; my $sender = 'sending email goes here'; my $reciever = 'recieve email goes here'; my $OutputFile = '/tmp/test.xls'; my $workbook = Spreadsheet::WriteExcel->new($OutputFile); my $TestReport = $workbook->add_worksheet('TestReport'); my $dbh = DBI->connect( $dsn, $usr, $pass, { RaiseError => 1, AutoCommit => 0 }) || die "Database connection not made: $DBI::errstr"; my $TestReportSQL = "SELECT FOO,BAR, BAZ FROM TABLENAME"; my $sth = $dbh->prepare( $TestReportSQL ) or die "Can't prepare SQL: $ +DBI::errstr"; $sth->execute(); my @arr1 = $sth->fetchall_arrayref({}); print Dumper @arr1; $TestReport->write('A1', [\@arr1] ); $workbook->close(); my $msg = MIME::Lite->new( From => "$sender", To => "$reciever", Type => 'multipart/mixed', Subject => "Test"); $msg->attach( Type => "AUTO", Path => "$OutputFile", Filename => "test.xls", Disposition => "attachment" ) or die "Error attaching file $OutputFile : $!\n"; $msg->send();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fix and email Spreadsheet::WriteExcel results.
by Corion (Patriarch) on Aug 08, 2011 at 14:24 UTC |