We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

insertHtml Custom Bullets in word document


Hi,
I would like to use a custom bullet style formatting after inserting some text into my word document with insertHtml method. I successfully manage to change the style of the text inside each ListItem Paragraph, but unfortunately i failed to change the bullet formatting itself. Is there a way to do that?
Here is my code:

Style customStyle = doc.getStyles().get(“customStyle”);//my custom style for bullets

builder.insertHtml(htmlContent);

Paragraphs paragraphs = doc.getFirstSection().getBody().getParagraphs();

int count = 0;

for(Node node : paragraphs.toArray()) {

Paragraph paragraph = (Paragraph) node;
if(paragraph.isListItem()) {

com.aspose.words.Style style = doc.getStyles().add(StyleType.PARAGRAPH, “MyStyle” + count++);

style.getFont().setBold(true);

//the following code has no effect on the bullet style
style.getListFormat().setList(doc.getLists().add(customStyle));

paragraph.getParagraphFormat().setStyle(style);
}
}


Thx in advance.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please try using the following code:

//Open document

Document doc = new Document("C:\\Temp\\in.doc");

//Get collection of Paragraphs

NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);

//loop through all parahraphs

for (int i = 0; i < paragraphs.getCount(); i++)

{

Paragraph par = (Paragraph)paragraphs.get(i);

//Check whether current paragraph is list item

if (par.isListItem())

{

//Change formating of the bullet

par.getListFormat().getListLevel().getFont().setBold(true);

}

}

//Save output document

doc.save("c:\\Temp\\out.doc");

see the following link for more information:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/com/aspose/words/listlevel.html

Hope this helps.

Best regards.


Hi,
Thanks for your help, the previous code works well for the text style of the ListItem. But i just want to change the shape (or the color) of the bullets itself used in my word document (after using insertHtml), from a circle to a triangle, or simply apply a custom one already defined in the document (in order to change the normal bullet shape by the one i called “customStyle”) :

Style customStyle = doc.getStyles().get(“customStyle”);//custom List style for bullets

Is it possible to do that?

Regards.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Yes, of course you can achieve this. Please try using the following code:

//Open document

Document doc = new Document("C:\\Temp\\in.doc");

//Get collection of Paragraphs

NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);

//Get style custom style

Style myLstStyle = doc.getStyles().get("myListStyle");

//Create new List from style defined in the document

List lst = doc.getLists().add(myLstStyle);

//loop through all parahraphs

for (int i = 0; i < paragraphs.getCount(); i++)

{

Paragraph par = (Paragraph)paragraphs.get(i);

//Check whether current paragraph is list item

if (par.isListItem())

{

//Set custom style

par.getListFormat().setList(lst);

}

}

//Save output document

doc.save("c:\\Temp\\out.doc");

Best regards,

I need this code also. However I can't seem to be able to create the equvilant code in VB. Ultimatly I would just like to force all bullets in the output word document to be Square for all levels. Is there a better way to do this? All content is being inserted with .insertHTML

Thanks,

-Jabin

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank for your request. I thin the following code could help you.

'Open a template document

Dim doc As Document = New Document("C:\Temp\in.doc")

'Get collection of Paragraphs from the document

Dim paragraphs As NodeCollection = doc.GetChildNodes(NodeType.Paragraph, True)

'Loop through all paragraphs

For Each par As Paragraph In paragraphs

'Check whether current paragraph is list item

If (par.IsListItem) Then

'If so, change its bullet

par.ListFormat.ListLevel.NumberStyle = NumberStyle.Bullet

par.ListFormat.ListLevel.Font.Name = "Wingdings"

par.ListFormat.ListLevel.NumberFormat = Chr(167)

End If

Next

'Save output document

doc.Save("C:\Temp\out.doc")

Best regards.

That is very close to what I need. However that code is also replaceing the numbers from numbered lists

    with the square bullet. Is it possible to also check for existing numbering before replacing with the square bullet? I see where to apply numbers etc but not where to check for existing number format.

    EDIT: I was able to make it work using this change to the code

    Dim paragraphs As NodeCollection = outputDoc.GetChildNodes(NodeType.Paragraph, True)

    'Loop through all paragraphs

    For Each par As Paragraph In paragraphs

    'Check whether current paragraph is list item

    If (par.IsListItem) Then

    If par.ListFormat.ListLevel.NumberStyle.Equals(NumberStyle.Bullet) Then 'If so, change its bullet style to SQUARE

    par.ListFormat.ListLevel.NumberStyle = NumberStyle.Bullet

    par.ListFormat.ListLevel.Font.Name = "Wingdings"

    par.ListFormat.ListLevel.NumberFormat = Chr(167)

    End If

    End If

    Next

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

It is nice that you have found solution.

Best regards.