Fellow Monks,
I am having database in MS Access. In a table, I have many columns in which some columns have normal text and some columns have object inserted through OLE (in my case, Word object has been inserted). By the below code, I can able to retrieve the data from the columns which has normal text and i can able to print in new document perfectly. But i cannot able to get the data properly from the column which has word object. When I write the data which I got from the word object in a new word document, I am getting junk characters. Is there any other way to retrive the data from the word object and write into another word document? Have anyone else come across with this type of work?
Also to check, i manually opened the word object link in the database and it has data in it.
Specifications: Perl 5.8.6, Windows 2000, MS Access 2000
use strict;
use warnings;
use DBI;
use Win32::OLE;
# check if Word exists and is running
my $word = Win32::OLE->GetActiveObject('Word.Application');
die "Word not Installed" if $@;
# start Word program instance if required or die if unable to
unless (defined $word) {
$word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit; } )
+ or die 'Cannot start Word';
}
# hide/show the document
$word->{Visible} = 0;
# Create new document
my $d = $word->Documents->Add;
# define selection
my $s = $word->Selection;
#set lines to be written to document
######################### retrive data from MS Access ################
+##
my $db_file = 'D:\test\Test2000Format.mdb';
my $dbh = DBI->connect(
'dbi:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source='.$db_file,
) or die $DBI::errstr;
my $sqlstatement="SELECT Library FROM Manuscripts"; #working perfectly
+, Library column has normal text
#$sqlstatement="SELECT MSContents FROM Manuscripts"; #MScontents colu
+mn has OLE word object
my $sth = $dbh->prepare($sqlstatement);
$sth->execute || die "Could not execute SQL statement ... maybe inv
+alid?";
#output database results
while (my @row = $sth->fetchrow_array)
{ print @row,"\n";
my $text = "@row"; #just for testing
$s->TypeText($text); #write in another new doc
}
# save our object
$word->WordBasic->FileSaveAs("D:\\test\\new.doc"); #new word document