cmi-docx
is a Python library for manipulating .docx files built on top of python-docx
. It extends the functionality of python-docx
by providing additional features and utilities for working with .docx files.
- Find and replace.
- Insert paragraphs in the middle of a document.
- Manipulate styles and formatting of paragraphs' substrings.
Install this package from pypi using your favorite package manager. For example, using pip
:
pip install cmi-docx
The following example demonstratesa few features of cmi-docx:
import docx
from cmi_docx import document
doc = docx.Document()
paragraph = doc.add_paragraph("Hello, world!")
extend_document = document.ExtendDocument(doc)
extend_paragraph = document.ExtendParagraph(paragraph)
# Find and replace text.
extend_document.replace("Hello", "Hi", {"bold": True})
# Insert and image
extend_document.insert_image(index=1, image_path="path/to/image.png")
# Reformat a paragraph
extend_paragraph.format(italics=True)