How to set word bullet style by appending the HTML code in C#

With the help of Spire.Doc for .NET, developers can easily set bullet style for the existing word documents via invoke p.ListFormat.ApplyBulletStyle() method to format. This article will show you how to convert HTML list into word and set the bullet style for the word list in C#.

Firstly, please view the effective screenshot for the result word document:

How to set word bullet style by appending the HTML code in C#

Here comes to the steps:

Step 1: Create a new document and add a section to the document.

Document document = new Document();
Section section=document.AddSection();

Step 2: Add word list to the paragraph by appending HTML.

Paragraph paragraph = section.AddParagraph();
paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");

Step 3: Set the bullet style for the paragraph.

foreach (Paragraph p in section.Paragraphs)
{
 p.ApplyStyle(BuiltinStyle.Heading2);
 p.ListFormat.CurrentListLevel.NumberPosition = 20;
 p.ListFormat.CurrentListLevel.TextPosition = 30;
 }

Step 4: Save the document to file

document.SaveToFile("result.docx",FileFormat.Docx);

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
namespace SetWordBullet
{
 class Program
    {
     
      static void Main(string[] args)
        {
            Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendHTML("
  1. Version 1
  2. Version 2
  3. Version 3
"); foreach (Paragraph p in section.Paragraphs) { p.ApplyStyle(BuiltinStyle.Heading2); p.ListFormat.CurrentListLevel.NumberPosition = 20; p.ListFormat.CurrentListLevel.TextPosition = 30; } document.SaveToFile("result.docx", FileFormat.Docx); } } }