I made for exporting a program, see if help:
procedure TfrmPrincipal.Word1Click(Sender: TObject);
var
WordApp, NewDoc, WordTable : OleVariant;
i : Integer;
s : string;
begin
if RichEdit1.Lines.Count > 1 then
begin
WordApp := CreateOleObject('Word.Application');
WordApp.Visible := True;
NewDoc := WordApp.Documents.Add;
WordTable := NewDoc.Tables.Add(WordApp.Selection.Range, 1, 1);
WordTable.Cell(1,1).Range.Paragraphs.Alignment := wdAlignParagraphcenter;
WordTable.Cell(1,1).Range.Paragraphs.SpaceAfter := 0;
WordTable.Borders.OutsideLineStyle := wdLineStyleSingle;
s := '';
for i := 1 to RichEdit1.Lines.Count-1 do
begin
s := s + RichEdit1.Lines.Strings[i]+#13+#10;
end;
s := Copy(s,1,Length(s)-2);
WordApp.Selection.Font.Size := 8;
WordApp.Selection.Font.Name := 'Courier New';
WordTable.Cell(1, 1).Range.Text := s;
// Cleanup...
WordApp := Unassigned;
NewDoc := Unassigned;
WordTable := Unassigned;
end;
end;
Dude, the one time I needed to mess with table in Word, I was able to insert lines, remove and change line data, but I couldn’t create it dynamically. So I had a template file with a one-row table, and I was inserting the other lines as needed. If this fits you, I’ll insert an answer showing you how.
– Roberto de Campos
@Robertofagundes, already helps, this way I can leave the table in a specific place of the file and go inserting data.
– Augusto Gomes de Oliveira