I used the inserthtml function to import a mass of text.
After this, i formatted my styles with this code, everything works, except the heading 1 & 2 are still not centered:
Thanks for your request. The problem occurs because formatting in MS Word can be specified on few levels. For example formatting of paragraphs can be specified via Paragraph Styles or as properties of paragraph itself (inline formatting). If, for example, in style you specify align center, but in paragraph properties you specify align right, the paragraph will be aligned right.
The solution is quite simple. You can just reset inline formatting of paragraphs. For example see the following code:
// Open your HTML document (I saved it to file).
Document doc = new Document(@"Test001\test.html");
// Change Heading 1 style.
doc.Styles[StyleIdentifier.Heading1].ParagraphFormat.Alignment = ParagraphAlignment.Center;
// Now find all paragraphs with Heading 1 style and reset style.
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph paragraph in paragraphs)
{
if (paragraph.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1)
{
paragraph.ParagraphFormat.ClearFormatting();
paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
}
}
// Save output document.
doc.Save(@"Test001\out.doc");