use Win32::OLE; use DBI; #//set up the spec for DBI $db_type = 'mysql'; $db_name = "jcu2"; $db_host_name = '127.0.0.1'; #$db_port = '3306'; $db_spec = "DBI:$db_type:$db_name:$db_host_name"; #//connect to the database my $dbh = DBI->connect($db_spec, undef, undef) or (print "Couldn't connect to $db_spec: $DBI::errstr\n" and die()); my $Class = "Word.Application"; my $File = "c:\\Windows\\Desktop\\text.doc"; my $Word = Win32::OLE->GetActiveObject( $Class ); if( ! $Word ) { $Word = new Win32::OLE( $Class, \&Quit ) || die "Can not create a '$Class' object.\n"; } # By default a Word COM object is invisible (not # displayed on the screen). # Let's make it visible so that we can see what we # are doing… $Word->{Visible} = 1; my $Doc = $Word->Documents->Add(); #Prepare the DBI for fetching and execution my $sth=$dbh->prepare("SELECT strengths,weaknesses,recommendations FROM RawText"); $sth->execute or die "Can't prepare SELECT sql statement:$DBI::errstr\n"; #Loop through the fetched data while (($s,$w,$r) =$sth2->fetchrow_array) { #Assign the fetched data to a series of VB calls #This in fact outputs the entire contents of the call made #to the mysql table my($range) = $Doc -> {Content}; $range -> InsertAfter($s); $range -> InsertAfter($w); $range -> InsertAfter($r); #I would like to now output the data in a series of #tables if possible $Word->$range->Tables->Add(2,2); #Doesn't work for starters } $Doc->SaveAs( $File ); $Doc->Save(); print "Hit enter to continue...\n"; ; $Doc->Close(); $sth->finish; $dbh->disconnect; sub Quit { my( $Obj ) = @_; $Obj->Quit(); }