Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active September 13, 2024 20:12
Paragraph Formatting in Word with Python. For more details: https://kb.aspose.com/words/python/paragraph-formatting-in-word-with-python/
import aspose.words as aw
import aspose.pydrawing as drawing
# Load the license
wordLic = aw.License()
wordLic.set_license("license.lic")
newDoc = aw.Document()
builder = aw.DocumentBuilder(newDoc)
# Set formatting
paragraphFormat = builder.paragraph_format
paragraphFormat.alignment = aw.ParagraphAlignment.JUSTIFY
paragraphFormat.left_indent = 45
paragraphFormat.right_indent = 45
paragraphFormat.space_after = 20
paragraphFormat.borders.horizontal.line_style = aw.LineStyle.DOUBLE
paragraphFormat.style.font.size = 12
paragraphFormat.style.font.bold = True
paragraphFormat.style.font.color = drawing.Color.blue
# Output text
builder.writeln("Word paragraph formatting refers to adjusting the appearance and layout of paragraphs in a document to improve readability and presentation.")
builder.writeln("Word also provides options to control spacing before and after paragraphs, which helps in creating visually appealing documents with clear structure.")
newDoc.save("Formatted.docx")
print ("Text formatted")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment