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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ArhiCoderConnect With a Mentor Commented:
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
 
hulkenAuthor Commented:
And how do I put it to the correct destination? (IE a merge field, or a column)
0
 
ArhiCoderCommented:
However, if you want to RTF file on out - just set:
val:='D:\\123.rtf';
0
All Courses

From novice to tech pro — start learning today.