What I'm trying to do is query a database and send an email with the results as an attached excel file using MIME::Lite and SpreadSheet::WriteExcel. Using data dumper I can see the data returning from the query. What is happening is that the attached excel file has has one row, not multiple rows (I see them via the dumper print), containing things like "HASH(0x975700)". What do I need to change to get one row per query result, populated with the vaules which are printed in by data dumper?
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();
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.