OLE Automation with word

Hello

I'm building a table inside a word document. One column should contain formated text- (I have it in rich text format)

Can anyone tell me how to do this in a better way than I'm doing now.

Currently I create the table with ConvertToTable
and loop through all rich texts and copy to clipboard and paste into the column in the table.

Working with tables are awful slow. I would prefere to use merge field or something like that but can't figure out how to feed them  with RICH text.
hulkenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hulkenAuthor Commented:
And how do I put it to the correct destination? (IE a merge field, or a column)
0
ArhiCoderCommented:
Hi, I usual use Word tables like that:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleServer, WordXP;

type
  TForm1 = class(TForm)
    WordApplication1: TWordApplication;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    val:OleVariant;
    row,col,i,j:Integer;
    t:Table;
    c:Cell;
begin
    row:=50;
    col:=6;
    val:=true;
    WordApplication1.Documents.Add(EmptyParam,EmptyParam,EmptyParam,val);
    with WordApplication1.ActiveDocument do
    begin
        Content.Text:='Test';
        val:='D:\\123.doc';
        Tables.Add(Content,row,col,EmptyParam,EmptyParam);
        t:=Tables.Item(1);
        for i:=1 to t.Rows.Count do
            for j:=1 to t.Columns.Count do
            begin
                c:=t.Cell(i,j);
                c.Range.Text:=IntToStr(i)+':'+IntToStr(j);
            end;
        SaveAs(val,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
    end
end;

end.

This code processing about 2 seconds on my PC. Not very slow for me.
Any questions?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArhiCoderCommented:
However, if you want to RTF file on out - just set:
val:='D:\\123.rtf';
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.