Hey Guys I need some help.  I have been working on this script for a
week now trying to out put my sql data into an excel macro.  I have
tried everything I know how to do and I need some direction.  Please
advise.

Heres my code:
#!perl

use DBI;
use IO::File;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';

$dbh = DBI->connect('dbi:ODBC:agent');

my $agnlst = 'agent_list.txt';
my $ticsub = 'ticket_scrub.txt';
my $out = IO::File->new(">$ticsub");

print "Connecting to Sql Database\n ";
sub agent_report {

my $agent= shift;

$sql = "SELECT tblScrubInfo.numTicketNumber, tblScrubInfo.txtAgentID,
tblScrubInfo.datDate, tblScrubInfo.txtCustomer,
tblScrubInfo.datDateIncidentWasNoted, tblScrubInfo.txtScrubingTech,
tblScrubDetail.txtCategory, tblScrubDetail.Description,
tblScrubDetail.ynWasFixed FROM tblScrubInfo, tblScrubDetail WHERE
txtAgentID='$agent' AND tblScrubInfo.numTicketNumber =
tblScrubDetail.numTicketNumber AND ynWasFixed= No ORDER BY txtCustomer
";

$sth = $dbh->prepare($sql);
$sth->execute ||
        die "Cannot open my $dbh ?";

while (@row=$sth->fetchrow_array)
{print $out "@row\n"}

}

print "Connection Successful - Fecthing Data \n";

open (LIST, "$agnlst") or die "Cannot open the agent $agnlst: $!\n";

while ( my $ca = <LIST> ){
        chomp ($ca);
        agent_report($ca);
}
close (LIST);

my $Excel = Win32::OLE-> new ('Excel.Application', 'QUIT') or
        die ("Cannot create new object: ", Win32::OLE->LastError());

        $Excel-> Sheet (QueryTables->Add) (Connection);
        $Excel-> {TEXT} ('C:\Perl\bin\ticket_scrub.txt',
(Destination->Range("A1"));
        $Excel-> {Name} = ticket_scrub;
        $Excel-> {FieldNames} = True;
        $Excel-> {RowNumbers} = False;
        $Excel-> {FillAdjacentFormulas} = False;
        $Excel-> {PreserveFormatting} = True;
        $Excel-> {RefreshOnFileOpen} = False;
        $Excel-> {RefreshStyle} = xlInsertDeleteCells;
        $Excel-> {SaveData} = True;
        $Excel-> {AdjustColumnWidth} = True;
        $Excel-> {RefreshPeriod} = 0;
        $Excel-> {TextFilePromptOnRefresh} = False;
        $Excel-> {TextFilePlatform} = xlWindows;
        $Excel-> {TextFileStartRow} = 1;
        $Excel-> {TextFileParseType} = xlDelimited;
        $Excel-> {TextFileTextQualifier} = xlTextQualifierNone;
        $Excel-> {TextFileConsecutiveDelimiter} = False;
        $Excel-> {TextFileTabDelimiter} = False;
        $Excel-> {TextFileSemicolonDelimiter} = False;
        $Excel-> {TextFileCommaDelimiter} = False;
        $Excel-> {TextFileSpaceDelimiter} = True;
        $Excel-> {TextFileColumnDataTypes} = Array(1, 1, 1, 1, 1, 1, 1,
1, 1, 1,);
        $Excel-> {Refresh BackgroundQuery} = False;
$Excel-> Workbook-> SaveAs = ('C:\Perl\bin\ticket_scrub.xls'); 


Heres the error message that I get when I run it.  I have read the
doucmentation and I think Im almost there but I need some direction.  

Documents and Settings\daniel\Desktop>perl agent.pl
syntax error at agent.pl line 43, near ") ("
syntax error at agent.pl line 44, near ");"
Execution of agent.pl aborted due to compilation errors.

C:\Documents and Settings\daniel\Desktop>

Reply via email to