views:

2181

answers:

1

Hi all,

I have a C# application which will open a word document and then replace some of the predefined bookmarks with the data which i have like Name,Class etc..

It is all are just string values .Now I want to render a Table with dynamic number of rows to the word document.I want the table in a particular place in the document.

Can i use bookmark for this.If so how ??? IS there any other method?

+3  A: 

hi ,

yes you can use book mar and also use fields to replace it with table with n no. of rows and n no. of columns.

you can loop through fields and get it's range and using range you can add table at field location...

e.g.

//CREATING OBJECTS OF WORD AND DOCUMENT

Word.Application oWord = new Word.Application();

Word.Document oWordDoc = new Word.Document();

foreach (Word.Field myMergeField in oWordDoc.Fields)

{

iTotalFields++;

Word.Range rngFieldCode = myMergeField.Code;

String fieldText = rngFieldCode.Text;



// ONLY GETTING THE MAILMERGE FIELDS

if (fieldText.StartsWith("tablename"))

{
    myMergeField.Select();
     oWordDoc.table.add(rngFieldCode,4//for rows,4// for colioulns,ref omising....);
 }

}

I hope you find your answer...

Thanks.

Paresh Koyani

thanks &