Oups! Sorry! I've forgot to mention I need it in VC++!
Main Topics
Browse All TopicsGreetings!
I have an template document in RTF-format. I need to insert a data from database in this template like a table.
For example I need to save 5 rows and 3 columns - How can I create this table and after that insert data in cells?
Regards!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Masonok:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
Business Accounts
Answer for Membership
by: vishaltPosted on 2003-05-12 at 01:23:19ID: 8507441
Here's a sample to insert a table into a rtf document using Word Automation through VB.
---------- ---------- ---------
tion")
:=0, End:=0)
kgroundPat ternColorI ndex = _ ent = wdAlignParagraphCenter
Also rtf files with tables are recognized in Wordpad (which seems to be a strict RTF Viewer).
Hence a Word Object is used to save the file in rtf format. It is properly recognized in MS-Word)
One can insert rows or columns dynamically & also address each cell of the table.
--------------------------
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Public Sub FillRow(Doc As Word.Document, Row As Integer, _
Text1 As String, Text2 As String, _
Text3 As String, Text4 As String)
With Doc.Tables(1)
' Insert the data into the specific cell
.Cell(Row, 1).Range.InsertAfter Text1
.Cell(Row, 2).Range.InsertAfter Text2
.Cell(Row, 3).Range.InsertAfter Text3
.Cell(Row, 4).Range.InsertAfter Text4
End With
End Sub
Private Sub Form_Load()
' Create an instance of Word and make it visible
Set wrdApp = CreateObject("Word.Applica
wrdApp.Visible = True
' Add a new document
Set wrdDoc = wrdApp.Documents.Add
wrdDoc.Select
Set myRange = ActiveDocument.Range(Start
wrdDoc.Tables.Add Range:=myRange, NumRows:=9, _
NumColumns:=4
With wrdDoc.Tables(1)
' Set the column widths
.Columns(1).SetWidth 51, wdAdjustNone
.Columns(2).SetWidth 170, wdAdjustNone
.Columns(3).SetWidth 100, wdAdjustNone
.Columns(4).SetWidth 111, wdAdjustNone
' Set the shading on the first row to light gray
.Rows(1).Cells.Shading.Bac
wdGray25
' Bold the first row
.Rows(1).Range.Bold = True
' Center the text in Cell (1,1)
.Cell(1, 1).Range.Paragraphs.Alignm
' Fill each row of the table with data
FillRow wrdDoc, 1, "Class Number", "Class Name", "Class Time", _
"Instructor"
FillRow wrdDoc, 2, "EE220", "Introduction to Electronics II", _
"1:00-2:00 M,W,F", "Dr. Jensen"
FillRow wrdDoc, 3, "EE230", "Electromagnetic Field Theory I", _
"10:00-11:30 T,T", "Dr. Crump"
FillRow wrdDoc, 4, "EE300", "Feedback Control Systems", _
"9:00-10:00 M,W,F", "Dr. Murdy"
FillRow wrdDoc, 5, "EE325", "Advanced Digital Design", _
"9:00-10:30 T,T", "Dr. Alley"
FillRow wrdDoc, 6, "EE350", "Advanced Communication Systems", _
"9:00-10:30 T,T", "Dr. Taylor"
FillRow wrdDoc, 7, "EE400", "Advanced Microwave Theory", _
"1:00-2:30 T,T", "Dr. Lee"
FillRow wrdDoc, 8, "EE450", "Plasma Theory", _
"1:00-2:00 M,W,F", "Dr. Davis"
FillRow wrdDoc, 9, "EE500", "Principles of VLSI Design", _
"3:00-4:00 M,W,F", "Dr. Ellison"
End With
wrdDoc.SaveAs "c:\test.rtf"
End Sub