Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-kb/2dc01b68804561383d844ef164bac4b9 to your computer and use it in GitHub Desktop.
Save aspose-com-kb/2dc01b68804561383d844ef164bac4b9 to your computer and use it in GitHub Desktop.
Convert Paragraph into Bullet Points in Word using Python. For more details: https://kb.aspose.com/words/python/convert-paragraph-into-bullet-points-in-word-using-python/
import re
import aspose.words as aw
from typing import cast
# Path to the source files
filePath = "c://word//"
# Load the Aspose.Words license in your application to remove bullets
aw.License().set_license(filePath + "Conholdate.Total.Product.Family.lic")
# Instantiate the Document class object to load the source word
srcDoc = aw.Document(filePath + "out.docx")
text = srcDoc.to_string(aw.SaveFormat.TEXT)
pattern = "(?<=[.!?])\s+"
sentences = re.split(text, pattern)
output = aw.Document()
builder = aw.DocumentBuilder(output)
builder.font.bold = True
builder.font.name = "Courier"
builder.font.size = 12
builder.list_format.list = output.lists.add(aw.lists.ListTemplate.BULLET_SQUARE)
for sentence in sentences:
builder.writeln(sentence.strip())
builder.list_format.remove_numbers()
output.save("bullet-sample.docx")
print ("Bullets added successfully")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment