Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Insert a row into an existing table in a Word document Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
06-May-04
Category
OLE
Language
Delphi 5.x
Views
209
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Sebastian Volland

I want to add rows to an existing table but have difficulties using InsertRows. 
Does anyone have an example?

Answer:

1   uses
2     ComObj;
3   
4   procedure TForm1.Button1Click(Sender: TObject);
5   var
6     App, WordDoc, tabelle: OLEVariant;
7   begin
8     try
9       {Create MSWord instance}
10      App := CreateOleObject('Word.Application');
11    except
12      {Error...}
13      Exit;
14    end;
15    {Open a Word Document}
16    WordDoc := App.Documents.Open('c:\test.doc');
17    {Insert a table}
18    tabelle := WordDoc.Tables.Add(App.Selection.Range, 5 {Columns}, 4 {Rows});
19    {Write sth into a cell}
20    tabelle.Cell(2 {Column}, 4 {Row}).Range.Text := '123';
21    {Append row to table}
22    
23  App.Selection.Tables.Item(1).Rows.Item(App.Selection.Tables.Item(1).Rows.Count).Sele
24  ct;
25    App.Selection.InsertRowsBelow;
26    {Set Column width}
27    App.Selection.Tables.Item(1).Columns.Item(1).SetWidth(ColumnWidth := 40,
28      RulerStyle := $00000000 {wdAdjustNone});
29    {Show MSWord}
30    App.Visible := True;
31    {Cleanup...}
32    App := Unassigned;
33    WordDoc := Unassigned;
34    tabelle := Unassigned;
35  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC