Last post May 11, 2010 01:54 AM by mahesh.anjani
May 10, 2010 08:54 AM|mahesh.anjani|LINK
I am doing find replace in word document using Word.Application and Word.Document it's working fine.
Issue - I have a table in word document now I want to generate table with the data fetched from database. Below given is the word table and code. The placeholder replaced but when I add new row a blank row added to the table without and
Code to replace:
Dim oTempRow As Word.Row
Dim oRow As Word.Row
For Each dr in DataTable.Rows
oTempRow = oDoc.Tables(1).Rows(1)
oRow = oDoc.Tables(1).Rows(1)
ReplaceText(oRow, #FtName#, dr("FirstName")
ReplaceText(oRow, #LName#, dr("LastName")
May 10, 2010 12:06 PM|qwe123kids|LINK
chk the above link
May 11, 2010 01:54 AM|mahesh.anjani|LINK
The link contains good information, but my scenario is little different. I am using an existing word document as template. I have to get the document and replace the placeholder and at the end save it with unique name. This is working fine.
The document contains following table.
I get a data table which I loop through and replace the placeholder. To do that first I assign the object of the second row into temparary Word.Row object, because for each row I would require these placeholders. And then replace placeholder into existing the
row. I add the temporary Word.Row object and repeat the first step again. This is the overall logic.
Now the issue is when I add the temporary Word.Row object to table, It adds a blank row without any placeholders event though it's a copy of row with placeholders.
Dim oTable As Word.Table = oDoc.Tables(1)
Dim oRow As Word.Row = oTable.Rows(2)
Dim oTempRow As Word.Row = oTable.Rows(2) 'Assign the row with placeholde
For Each dr As DataRow In dsTasks.Tables(0).Rows
oRow = ReplaceText(dr, oRow)
oTable.Rows.Add(oTempRow) 'Again add the row with placeholder