This is what i am doing right now
foreach (var objField in objMainDoc.Descendants<SimpleField>())
{
string strFieldName = GetFieldName(objField);
if (!string.IsNullOrEmpty(strFieldName))
if (values.ContainsKey(strFieldName) && !string.IsNullOrEmpty(values[strFieldName]))
string strRunProp = null;
if (objField != null)
foreach (RunProperties objRP in objField.Descendants<RunProperties>())
strRunProp = objRP.OuterXml;
break;
}
Run objRun = new Run();
if (!string.IsNullOrEmpty(strRunProp))
objRun.Append(new RunProperties(strRunProp));
//add the text to the place holder
//objRun.Append(new Text(values[strFieldName]));
objRun.Append(new RunProperties(tbl));
//replace the merge field with the value
// objField.Parent.ReplaceChild<SimpleField>(objRun, objField);
// objField.Parent.ReplaceChild<SimpleField>(tbl , objField);
i want to insert table into perticular fields in word docx file.
The problem is that I'm getting this exception:
Cannot insert the OpenXmlElement "newChild" because it is part of a tree.