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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft Word Output

Status
Not open for further replies.

gshirey

Programmer
Apr 11, 2001
12
0
0
US
I have a slight delima. I have designed a pretty efficient, easy to use quote generation system for my company. It works great for building routine quotes for customers. It generates an html output based on the salespersons criteria. Lately however, I have seen that more often than not quotes are needing to be edited slightly after completion. This requires me to work with the ouputed html. The changes seem to follow no particular pattern (a note to buyer here, an unusual item there) such that if the front end were changed to accomodate such changes, the interface would no longer be simple enough for my sales staff to use.

My main thought for solution was to create a MS Word document rather than an html doc. That way, the person building the quote can make changes themselve. I am trying to work with the win32:eek:le module, but am having no luck interfacing with Word. In the past I have made decent scripts that interact with MS Excel, but none with Word. Does anyone know of any good documentation to interfacing with Word.

Or, does anyone have a better solution alltogether?


Thanks for your help.
 
1. You can write RTF form you perl script. Word can read RTF-files. Drawback: You must be familiar with RTF.

2. Use Word's macro recorder to get an idea of how to solve the task via OLE automation. The recorded macro shows the used objects with their properties and methods. Then simply translate it from VBA to perl.

Your word appplication should start like this:
Code:
#	Start Word Application or use existing
my $WordApp = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', sub {$_[0]->Quit;});
my $WordDoc = $WordApp->Documents->Open('myWordFile.doc');
my @fnames;

my $fieldCt = $WordDoc->FormFields->Count;
for (my $i = 1; $i <= $fieldCt; $i++) {
	my $fname = $WordDoc->FormFields($i)->Name;
	push @fnames, $fname;
}
$WordDoc->Close();
@fnames now holds a list of all document's form field names.

Thomas
 
Thomas is quite right, Word can read .rtf files but it can also read .html files as well. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks all,

I think editing the html in Word may be the solution. I knew if I posted I could save a lot of work.
 
Yes, Word can read HTML, but RTF is not all that hard:

1. Make a sample of your document in Word, then save as RTF. Examine the output, and see where you need to replace with variables. This can get messy for big documents, but if most of it is just looping through results, it can be very easy.

2. Here is a link at CPAN for the &quot;RTF Cookbook&quot;:
3. If you don't mind branching out and trying a little PHP, the next version of PHP will come with an RTF extension.

4. Here is the official Microsoft RTF specification:
-------------------

Current reading --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top