Hi Mani,
Thanks for your inquiry. Please note that formatting is applied on a few different levels. For example, let’s consider formatting of simple text. Text in documents is represented by Run element and a Run can only be a child of a Paragraph. You can apply formatting
- to Run nodes by using Character Styles e.g. a Glyph Style,
- to the parent of those Run nodes i.e. a Paragraph node (possibly via paragraph Styles)
- you can also apply direct formatting to Run nodes by using Run attributes (Font). In this case the Run will inherit formatting of Paragraph Style, a Glyph Style and then direct formatting.
In your case we suggest you please remove the formatting applied to Run nodes and use ImportFormatMode.UseDestinationStyles in Document.AppendDocument method. Please read the following article:
Differences between ImportFormat Modes
Document document = new Document(strTemplateFile);
Document docHtml = new Document(strHtmlFile);
document.AppendDocument(docHtml, ImportFormatMode.UseDestinationStyles);
document.UpdateFields();
document.UpdateTableLayout();
foreach (Paragraph paragraph in document.GetChildNodes(NodeType.Paragraph, true))
{
foreach (Run run in paragraph.Runs)
{
run.Font.ClearFormatting();
}
}
document.Save(strResultFile, SaveFormat.Docx);