vimwiki/tech/python-docx.wiki

46 lines
988 B
Plaintext

= Python docx =
Python docx is a library for generating a .docx file with python code
== Setup ==
{{{
from docx import Document
from docx.shared import Inches
}}}
== Metadata ==
There is document metadata, stored in `Document.core_properties`. Edit these
values to change metadata.
== Functions ==
=== Add headings ===
`add_heading(text, level)`, where text is the text to add, and level is the
size, 0-9, where 0 is the largest.
=== Add paragraphs ===
`add_paragraph(text, style)` where text is the text to add, and style is the
style to apply. Note that `\n`, `\r`, etc work in the text field.
=== Page break ===
`add_page_break()` adds a page break.
== Style ==
=== Lists ===
There are two built in lists, `List Number` and `List Bullet`. `List Number`
incremements each time it is added to a paragraph and creats a numbered list.
Same applied to `List Bullet`.
== Tables ==
Tables are added via the `add_table(rows, cols, style)` function of the
`Document` class.