On 18.01.2009 03:18, gregarican wrote:
> On Jan 17, 11:18 am, Phlip <phlip2... / gmail.com> wrote:
>> Robert Klemme wrote:
>>> I'd do it with VB from inside Word.  An alternative might be to use
>>> OpenOffice, read the word, write OO's format (XML in ZIP) and the
>>> manipulate the XML.  But this sounds pretty awkward.
>> I suspect Word can also barf out an XML representation.
>>
>> It may be awkward (get ready for the horror when you open that file!), but it's
>> probably the best way. All word processing is heading towards XML for its
>> interoperability.
> 
> I wound up writing a C# console program to do the work. I just
> referred to ugly underbelly of all of the Word COM stuff and was able
> to grab what I needed. It took awhile though, since my text was
> contained within text frames. So I had to work with the
> Document.Shapes property and whatnot.

I'd say that's pretty fast.  Good job!

> In searching for a solution I did run across a VBA code snippet that
> would save off each document separately after the mail merge
> completed. At least now I have a totally automated solution, although
> it's cobbled together from various sources. First I pull my data from
> a SQL DB using Ruby, dumping that to an Excel data source. Then I have
> a C# program that takes that data source, uses a Word mail merge
> template and delivers the final document set. Finally, I have a Ruby
> program that looks in that save directory and e-mails the documents to
> the individual employees. Eventually it'd be a lot cleaner and easier
> to maintain if I had all of the work done in a single program written
> in a single language. But that's another fight for another day :-)

May I suggest a different approach?  Since your primary step is pulling 
data from a relational DB using Ruby, you could as well do this: open 
the mail merge Word template, replace mail merge fields with text with 
special formatting (for example "<<<field name>>>" or whatever doesn't 
collide with RTF meta sequences).  Then you save this as RTF file (ASCII 
readable).  Now you only need to read in the mail template file from 
Ruby, do all the replacements and then write it out in Ruby again once 
for each record.  Sounds pretty simple IMHO.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end