[DUG] Word Automation

Brian Wrigley bswrigley at xtra.co.nz
Tue Apr 3 15:04:51 NZST 2007


Hi Dave,

I did some work a few years ago in Delphi (4) inserting pictures into Word
(97) documents. I didn't use a 3rd-party component, just instantiated a Word
object, leading to code like this:

I := varW.ActiveDocument.shapes.count;
while I > NumShapes do begin
  varW.ActiveDocument.Shapes.Item(I).ConvertToInlineShape;
  I := I - 1;
  end;

I := varW.ActiveDocument.Inlineshapes.count;
while I > NumInlineShapes do begin
  CurrentPic := varW.ActiveDocument.InlineShapes.Item(I);

  Currentpic.Fill.Visible := msoFalse;
  Currentpic.Fill.Transparency := 0.0;
  (etc)

You probably need to study the Word DOM and get access to the Word object
directly if the component you're using doesn't expose the properties and
sub-objects that you need. eg you may need to instantiate an object that
represents the array you're working with, which probably has properties such
as number of rows, number of columns, and then a collection of sub-objects
representing rows or cells or both.

One thing that may help is to go through the sequence of actions in Word
with the macro recorder running, then examine the vba code that it writes to
perform it.

Hope this helps,
Brian


----- Original Message -----
From: "Dave O'Brien" <dave at iccs.co.nz>
To: "NZ Borland Developers Group - Delphi List" <delphi at ns3.123.net.nz>
Sent: Tuesday, April 03, 2007 11:09 AM
Subject: [DUG] Word Automation


> I am attempting to use winword (2003) as a base for reports using the
TOpWord component. I have managed to open a template and do replaces on tags
in the document, save etc, but now need to deal with populating a table
(variable rows, fixed columns).
>
> I'm not having much luck working this out. Does anyone have a bit of
example code to show how to do this? Or is there a better way?
>
> Cheers,
> David O'Brien.



More information about the Delphi mailing list