Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Retrieve data from MS Access which has Columns with OLE Object

by prasadbabu (Prior)
on May 18, 2006 at 14:23 UTC ( [id://550243]=perlquestion: print w/replies, xml ) Need Help??

prasadbabu has asked for the wisdom of the Perl Monks concerning the following question:

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

Prasad

Replies are listed 'Best First'.
Re: Retrieve data from MS Access which has Columns with OLE Object
by JamesNC (Chaplain) on May 19, 2006 at 01:55 UTC
    From what you are saying, you are retrieving a copy of an object from the database which would be a binary word doc object( or it could be some other VBA Object?). If you wanted to retrieve the text from that object, then you could try to operate on that object with a OLE method it would understand. You may have to first create another OLE word object and then set it equal to the object you retrieve from the database and then grab the text using OLE. As it is, I would expect it to garbled, it is an object and not text.

    JamesNC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://550243]
Approved by Corion
Front-paged by holli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-25 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found