EDN Admin
Well-known member
[background=#f0f3f4]
In my web app, i see an error when doing mail merge,[/background][background=#f0f3f4]
The : character, hexadecimal value 0x3A, cannot be included in a name.[/background][background=#f0f3f4]
Below is the code:[/background] Public ReadOnly Property XMLNS() As XNamespace
Get
Return XNamespace.[Get](WORDMLNS)
End Get
End Property
Public Const WORDMLNS As String = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
Dim newBody As XElement = XElement.Parse(wordDocument.MainDocumentPart.Document.Body.OuterXml)
Get all Mail Merge Fields
Dim mailMergeFields As IList(Of XElement) = (From el In newBody.Descendants() Where el.Attribute(Convert.ToString(XMLNS) & "instr") IsNot Nothing Select el).ToList()
Replace all merge fields with Data
For Each field As XElement In mailMergeFields
Dim fieldName As String = field.Attribute(Convert.ToString(XMLNS) & "instr").Value.Replace("MERGEFIELD", String.Empty).Trim().Replace("""", "")
If fieldNameList.Contains(fieldName) Then
Dim newElement As XElement = field.Descendants(Convert.ToString(XMLNS) & "r").First()
newElement.Descendants(Convert.ToString(XMLNS) & "t").First().Value = GetFieldValue(fieldNameList, fieldValueList, fieldName)
field.ReplaceWith(newElement)
End If
Next[background=#f0f3f4]
Underlined throws the error...[/background][background=#f0f3f4]
Can anyone please let me know why it would do that?[/background][background=#f0f3f4]
Appreciate the help[/background][background=#f0f3f4]
Thanks[/background]
View the full article
In my web app, i see an error when doing mail merge,[/background][background=#f0f3f4]
The : character, hexadecimal value 0x3A, cannot be included in a name.[/background][background=#f0f3f4]
Below is the code:[/background] Public ReadOnly Property XMLNS() As XNamespace
Get
Return XNamespace.[Get](WORDMLNS)
End Get
End Property
Public Const WORDMLNS As String = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
Dim newBody As XElement = XElement.Parse(wordDocument.MainDocumentPart.Document.Body.OuterXml)
Get all Mail Merge Fields
Dim mailMergeFields As IList(Of XElement) = (From el In newBody.Descendants() Where el.Attribute(Convert.ToString(XMLNS) & "instr") IsNot Nothing Select el).ToList()
Replace all merge fields with Data
For Each field As XElement In mailMergeFields
Dim fieldName As String = field.Attribute(Convert.ToString(XMLNS) & "instr").Value.Replace("MERGEFIELD", String.Empty).Trim().Replace("""", "")
If fieldNameList.Contains(fieldName) Then
Dim newElement As XElement = field.Descendants(Convert.ToString(XMLNS) & "r").First()
newElement.Descendants(Convert.ToString(XMLNS) & "t").First().Value = GetFieldValue(fieldNameList, fieldValueList, fieldName)
field.ReplaceWith(newElement)
End If
Next[background=#f0f3f4]
Underlined throws the error...[/background][background=#f0f3f4]
Can anyone please let me know why it would do that?[/background][background=#f0f3f4]
Appreciate the help[/background][background=#f0f3f4]
Thanks[/background]
View the full article