I created template document with couple of mergefields and I wanted to fill them with values from c# app. Problem is because I cant find way to replace OpenXml SimpleField with text. There is a ton of articles how to replace FieldCode with value, but I didn't find any with SimpleField. What is appropriate way do that?
Asked
Active
Viewed 113 times
1 Answers
0
Well, apparently replacing a SimpleField with text is not that difficult. Maybe it's not the best solution, but one possible approach is to search for the first Text element and replace it with the desired text.
public static void ReplaceWithText(this SimpleField field, string replacementText)
{
Text t = field.Descendants<Text>().FirstOrDefault();
if (t != null)
{
t.Text = replacementText;
}
}

Martin Vecchione
- 66
- 2