Change the bullet style

Hi,

I can’t find any solution on your documentation or forum about how to modify bullet style.

I have some HTML with CSS to insert into a Content Control of a Word Document, so I use DocumentBuilder then insert html but I need to change the style of the bullet to a custom one. I tried to use ParagraphFormat.ListFormat but I don’t know how to use it and there is no sample about it or doc…

Find the sample code below :

C#

var path = HttpContext.Server.MapPath(@"~\Areas\CFM\Template\CFM_Template_18-06-2014.docx");
Document doc = new Document(path);
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.RichText && sdt.Tag == "SummaryDescription")
    {
        var html = "- tes";
        sdt.RemoveAllChildren();
        var p = new Paragraph(doc);
        sdt.AppendChild§;
        builder.MoveTo(sdt.FirstChild);
        builder.InsertHtml(html);
        doc.Save(@"C:\out.docx");
    }
}

Css file:

ul {
list-style-image: url("/Content/images/prisme.png");
/*list-style-image: url("…/…/Content/images/prisme.png")*/
}
ol {
list-style-image: url("/Content/images/prisme.png")
/*list-style-image: url("…/…/Content/images/prisme.png")*/
}

cf. attached file

Please provide a solution.

This message was posted using Email2Forum by Babar Raza.

Hi there,

Thanks for your inquiry. Please use ListFormat.List property to get or set the list this paragraph is a member of. Please use the following code example to achieve your requirements. Hope this helps you.

If you still face problem, please share your input and expected output documents here for our reference. We will then provide you more information about your query along with code.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a list with tick based on one of the Microsoft Word list templates 
List list = doc.Lists.Add(ListTemplate.BulletTick);
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.RichText && sdt.Tag == "SummaryDescription")
    {
        var html = "- test";
        sdt.RemoveAllChildren();
        var p = new Paragraph(doc);
        sdt.AppendChild(p);
        builder.MoveTo(sdt.FirstChild);
        builder.InsertHtml(html);
        doc.Save(MyDir + "Out2.docx");
        //Apply BulletTick to existing list items
        foreach (Paragraph paragraph in sdt.GetChildNodes(NodeType.Paragraph, true))
        {
            paragraph.ListFormat.List = list;
        }
    }
}
doc.Save(MyDir + "Out.docx");

Hello,

Thank you for your reply. However I don’t want to apply a bullet from Word, I want to apply a custom bullet which is picture bullet.

Maybe there is a way by specifying the style of a bullet.

For example I have set a particular style default to my document and I set a picture bullet for the style “.Bullet 1”.

Then imagine I have into my html this code

var html = "Hello this is - a test again!";

I want to apply the picture bullet I have set to the style .Bullet 1 to any

tags when I’m inserting the html code into my document.

FYI Aspose Words version 14.9

Thank you for your help.

Hi there,

Thanks for your inquiry. Please use the following code example to
achieve your requirements. Hope this helps you.

Document doc = new Document(MyDir + "template.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Style listStyle = doc.Styles["Bullet 1"];
// This creates a list based on the list style.
Aspose.Words.Lists.List list1 = doc.Lists.Add(listStyle);
var html = "Hello this is - a test   again!";
builder.InsertHtml(html);
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (para.IsListItem)
    {
        para.ListFormat.List = list1;
    }
}
doc.Save(MyDir + "Out.docx");

Thank you for your answer! I found the solution you provided earlier and apply my bullet style anywhere in the document I wanted.

Thank you for your help!

Hi there,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.