Articles   Members Online: 3
-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 create tables in Word 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
15-Oct-02
Category
OLE
Language
Delphi 2.x
Views
49
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Is is possible to create a table in Word via OLE Automation and to specify the 
value of each cell?

Answer:

Yes. If Doc is a TWordDocument, for example:

1   { ... }
2   var
3     Tbl: Table;
4     R: Range;
5     Direction: OleVariant;
6     { ... }
7   Direction := wdCollapseEnd;
8   R := Doc.Range;
9   R.Collapse(Direction);
10  Tbl := Doc.Tables.Add(R, 2, 4, EmptyParam, EmptyParam);
11  Tbl.Cell(1, 1).Range.Text := 'Row 1, Col 1';
12  Tbl.Cell(1, 2).Range.Text := 'Row 1, Col 2';
13  
14  //But doing things with individual table cells in Word is extremely slow. If you 
15  can, it's better to enter the data as (for example) comma-separated values and 
16  convert it into a table only as the last step. Here'
17  
18  { ... }
19  const
20    Line1 = 'January,February,March';
21    Line2 = '31,28,31';
22    Line3 = '31,59,90';
23  var
24    R: Range;
25    Direction, Separator, Format: OleVariant;
26  { ... }
27  R := Word.Selection.Range;
28  Direction := wdCollapseEnd;
29  R.Collapse(Direction);
30  R.InsertAfter(Line1);
31  R.InsertParagraphAfter;
32  R.InsertAfter(Line2);
33  R.InsertParagraphAfter;
34  R.InsertAfter(Line3);
35  R.InsertParagraphAfter;
36  Separator := ',';
37  Format := wdTableFormatGrid1;
38  R.ConvertToTable(Separator, EmptyParam, EmptyParam, EmptyParam, Format, EmptyParam,
39    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
40    EmptyParam, EmptyParam);
41  { ... }


			
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