Applying bulleted paragraph styles not working correctly

I’m generating a Word document by moving to bookmarks and inserting HTML strings via the builder.InsertHtml method. I’m then iterating through the inserted paragraphs and applying the correct user-defined styles for the section. In several sections, the style is a bulleted paragraph style (the mouse-over for the style reads:

BulletA: Normal + Font: (Default) Arial, 10 pt Font color: Custom Color (RGB(99, 107, 112)), Indent: Left: 0.06", Hanging: 0.25", Space After: 3pt, Tabs: 0.31", Left, Outline Numbered + Level 1 + Numbering Style: Bullet + Aligned at: 1.88" + Tab after: 2.13" + Indent at 2.13"

My code (below) inserts my code correctly and appears to apply the correct style (when I put my cursor on the inserted text, the style drop down reads BulletA), but the spacing and indention are not correct. If I then choose the style and manually reapply it to the selected paragraph within Word, the spacing and idention are then correct.

startParagraph = builder.CurrentParagraph;
builder.InsertHtml(sbSchool.ToString());
paragraph = builder.CurrentParagraph;
// Iterate thorugh all paragraphs inserted by DocumentBuilder and change the bullet of the list items to dash.
while (paragraph != startParagraph)
{
// set the desired formatting for inserted html here.
paragraph.ParagraphFormat.StyleName = “BulletA”;
paragraph = (Paragraph)paragraph.PreviousSibling;
}
paragraph.ParagraphFormat.StyleName = “BulletA”;


Am I missing something in applying these bullet styles? I’ve double-checked, and they are paragraph styles and not list styles. Attached is a copy of the generated document. If you look under the Education section at the end of the document, I’ve manually reapplied the BulletA style to the first item but not the second. All items under the Membership section should also be BulletA style.

Hi,

Thank you for considering Aspose.Words. Actually the cause seems to be as follows. When you insert HTML text to the document via Aspose.Words, the newly inserted paragraphs already have some direct formatting. When you then apply a style to those paragraph, the direct formatting does not get removed but simply overrides certain formatting properties. This behaviour differs from Microsoft Word which does clear direct formatting when applying a style.

You can easily clear direct paragraph formatting before applying a style:

para.ParagraphFormat.ClearFormatting();

and then applying a style should work as expected.

Please let me know if it works to you.