Skip to content

Writer

Converts the Document model into DOCX bytes.

docwow.writer.docx_writer.write_docx(doc, target=None)

Write a Document to a DOCX byte string.

Parameters:

Name Type Description Default
doc Document

The document model to serialise.

required
target str | Path | None

Optional file path. When provided the bytes are also written to disk.

None

Returns:

Type Description
bytes

The raw DOCX bytes (a valid ZIP archive).

docwow.writer.document_writer.build_document_xml(doc, image_rids, hyperlink_rids=None, hf_rids=None)

Build word/document.xml.

Parameters:

Name Type Description Default
doc Document

The Document model.

required
image_rids dict[str, str]

Mapping {original_relationship_id → new_rid} for images.

required
hyperlink_rids dict[str, str] | None

Mapping {url → rid} for hyperlink relationships.

None
hf_rids dict[tuple[str, str], str] | None

Mapping {("header"|"footer", type) → rid} for header/footer relationships (e.g. ("header", "default") → "rId5").

None

Returns:

Type Description
bytes

UTF-8 bytes of the complete document.xml.

docwow.writer.styles_writer.build_styles_xml(styles)

Build word/styles.xml from the document's style definitions.

docwow.writer.numbering_writer.build_numbering_xml(numbering)

Build word/numbering.xml from numbering definitions.