Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output in MS Word

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hi All, I have a M$ word document (letter.doc) stored in /usr/local/apache/cgi-bin/letter.doc

I wrote a perl code in which each time user inputs some value like name, address the output word document customize according to the input.

the letter.doc looks like this
----------------------------
in(today)

in(address)

Dear in(name),
Blabal ablan blah blah blah


Thank you
------------------------------

i replace in(today),in(address) ,in(name) with values using the following code.

when i try run the script in web brower /usr/local/apache/cgi-bin/test_letter.pl

it fires up word application .But its not outputting any content what am i doing wrong here ...

Code:
#!/usr/bin/perl
use CGI;
$op=new CGI;

$in{name}="My Name is"
$in{address}=" address";
$in{today}="23/03/05";

&out("letter.doc");

   sub out
     {
     
       print "Content-type: application/msword", "\n\n";
       local($file)=@_;
       open(OUT,"$file") || print "$!: $file <br>";
       while(<OUT>)
       {
         $_ =~ s/in\((\w+)\)/$in{$1}/g;
         print;
       }
       close OUT;
     }

Thank you for any insight
 
It looks like you are opening word and writing to a file named letter.doc

There is no use of OLE to communicate to MS word that you want to open letter.doc in the application.

I have not done this myself, but I am pretty sure you need to use an OLE module of some sort.

Search the PERL forum for word application and you might find some helpful hints.


Michael Libeson
 
Thanks Mike,

Actually i am not creating word document.
I am placing word document file letter.doc file and replacing dynamic variables in it like in(name) in(address) etc ..I assume on the server end it act as a raw text file. If i view letter.doc as a text file. I can see all the variable are replaced by approriate values.

Another problem is how to present the word document in cgi-bin directory to browser for viewing.

May be i am missing something here ..as you said may be i need a OLE to communicate.




 
You will want to do something like this:

Code:
#!perl

use Win32::OLE;

my $today = "whatever";
my $address = "whatever";
my $name = "whatever";

my $_app_object = (Win32::OLE->GetActiveObject('Word.Application') ||
                   Win32::OLE->new('Word.Application'));

$_app_object->Selection->TypeText({Text => 'In' "$today"});
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeText({Text => 'in'"$address"});
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeText({Text => 'Dear in' "$name" ';'});
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeText({Text => 'blah blah blah'});
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeParagraph();
$_app_object->Selection->TypeText({Text => 'Thank you.'});

If what you want to do is in fact create a word document on the fly.

But I'm not sure excatly if that's what you want to do after reading your second post.

HTH
 
Thanks Wraheem, This works in *nix?

 
99.9% sure the answer is nope. But there should be a way to create a document under the same type way using whatever word processing app in whatever flavor of *nix your using (ie OpenOffice).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top