Insert table into word in C#

I create instance of Document class

Microsoft.Office.Interop.Word.Document

How i can insert table and text into special position in Document ? For example after or before one bookmark

Upvotes: 1

Views: 3204

Answers (1)

riteshmeher
riteshmeher

Reputation: 874

To add text in word doc, you can use

Word.Range rng = this.Application.ActiveDocument.Range(0, 0);
 rng.Text = "New Text";

for table:

 Word.Range tableLocation = this.Range(ref start, ref end);
 this.Tables.Add(tableLocation, 10, 11);

check this link for text and table.

Set rangeStart = ActiveDocument.Bookmarks("YourFirstBookmark").Range
Set rangeEnd = ActiveDocument.Bookmarks("YourEndBookmark").Range

var range= Range(rangeStart.Start, rangeEnd.End)

Upvotes: 3

Related Questions