It's well known that we can add a variety of bullet styles to paragraphs in Word, such as various symbols, pictures, fonts and numbers. Bullet makes these paragraphs to be a bulleted list, so that we can easily create a well-structured and professional document.
This article will demonstrate how to set bullet style for word paragraphs in WPF applications using Spire.Doc for WPF.
Below is the effective screenshot after setting bullet style:
Code snippets:
Use namespace:
using System.Windows; using Spire.Doc; using Spire.Doc.Documents;
Step 1: Create a new instance of Document class and load the sample word document from file.
Document doc = new Document(); doc.LoadFromFile("Instruction.docx");
Step 2: Create a bulleted list.
Get the first section, then apply bullet style to paragraphs from 5th to 13th and set bullet position.
Section sec = doc.Sections[0]; for (int i = 4; i < 13; i++) { Paragraph paragraph = sec.Paragraphs[i]; paragraph.ListFormat.ApplyBulletStyle(); paragraph.ListFormat.CurrentListLevel.NumberPosition = -20; }
In addition, we can also use following code to create a numbered list:
paragraph.ListFormat.ApplyNumberedStyle();
Step 3: Save and launch the file.
doc.SaveToFile("Bullet.docx", FileFormat.Docx); System.Diagnostics.Process.Start("Bullet.docx");
Full codes:
private void button1_Click(object sender, RoutedEventArgs e) { //Load Document Document doc = new Document(); doc.LoadFromFile("Instruction.docx"); //Set Bullet Style Section sec = doc.Sections[0]; for (int i = 4; i < 13; i++) { Paragraph paragraph = sec.Paragraphs[i]; //Create a bulleted list paragraph.ListFormat.ApplyBulletStyle(); //Create a numbered list // paragraph.ListFormat.ApplyNumberedStyle(); paragraph.ListFormat.CurrentListLevel.NumberPosition = -20; } //Save and Launch doc.SaveToFile("Bullet.docx", FileFormat.Docx); System.Diagnostics.Process.Start("Bullet.docx"); }