Populate or Fill MergeFields in Footer RRS feed

  • Question

  • Hello

    I am working on populating mergefields in footer. Template created in Word 2007. I am able to read the attributes and set the values to the mergefields but its not saving the changes and new word document created from a template still shows the mergefield & not its value.

    Any idea how i can save the changes.

    I appreciate your help.






    Each footPart As FooterPart In wordDocument.MainDocumentPart.FooterParts()


          Dim newFooter As XElement = XElement.Parse(footPart.Footer().OuterXml)



          Dim footerMergeFields As IList(Of XElement) = (From el In newFooter.Descendants() _



                                     Where el.Attribute(XMLNS + "instr") IsNot Nothing _



                                     Select el).ToList()



          ''Replace all merge fields with data


          For Each footerMergeField As XElement In footerMergeFields





                Dim footerField As String = footerMergeField.Attribute(XMLNS + "instr").Value.Replace("MERGEFIELD"            String.Empty).Trim()



                Dim row3 As DataRow



                If ds1.Tables(0).Columns.Contains(footerField) Then

                   row3 = ds1.Tables(0).Rows(0)


                   Dim newFooterElement As XElement = footerMergeField.Descendants(XMLNS + "r").First()

                   newFooterElement.Descendants(XMLNS +


    "t").First().Value = row3.Field(Of String)(footerField)





    End If


    Catch ex As Exception


    End Try






    Monday, April 5, 2010 2:01 PM

All replies