InsertHtml() with <h1> tag


#1

Hi,

We are trying to use DocumentBuilder.InsertHtml() function to insert html text with

tag, the following is our code,

builder.InsertHtml("

Header 1

");

The resulted word document correctly recognized "Heading 1" style, however, we found that the style name is not exact "Heading 1", it is something like "Heading 1 + After: 14 pt", we want the style to be exactly "Heading 1", is there a way that we can achieve this?

Thank you very much.
Yingbiao


#2

Hi

Thanks for your request. You can use Document builder to change formatting of any node in document. See the following code snippet.

//insert HTML

builder.InsertHtml("

Heading 1

");

//detect index of current paragraph

int index = builder.CurrentSection.Body.Paragraphs.IndexOf(builder.CurrentParagraph);

//move to previouse paragraph

builder.MoveToParagraph(index - 1, 0);

//clear formating of paragraph

builder.CurrentParagraph.ParagraphFormat.ClearFormatting();

//set "Heading 1" style for paragraph

builder.CurrentParagraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

//return to current paragraph

builder.MoveToParagraph(index, 0);

I hope that it will help you.