Python API
Type hints show ordinary inputs. For factories, awaitables and property references, see deferred values.
rocx.declarative
Declarative API for creating Word documents.
BlockContentControl
dataclass
Bases: Component
Rich-text control grouping paragraphs and tables within a story.
BookmarkTarget
dataclass
An internal hyperlink target, resolved by document-wide bookmark name.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
A Word-compatible bookmark name; may be deferred. |
Break
dataclass
Bases: Component
A line or page break.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
Type of break ('line', 'page', 'column', 'textWrapping'). |
CellBorder
dataclass
Defines a border for an individual table cell.
Attributes:
| Name | Type | Description |
|---|---|---|
side |
Literal['top', 'bottom', 'start', 'end']
|
The side of the cell for the border. Valid sides are |
val |
Literal['single', 'dashed']
|
The type of border line. |
sz |
int
|
Size of the border in eighths of a point (8 = 1pt). |
color |
tuple[int, int, int]
|
Color of the border as an RGB tuple; each component 0-255. |
hex_color
property
Color as uppercase hexadecimal string (no leading '#').
CellMargins
dataclass
Cell-local margin overrides, independent of table defaults or bidi layout.
Attributes:
| Name | Type | Description |
|---|---|---|
top |
float | None
|
Optional nonnegative points above content. |
start |
float | None
|
Optional nonnegative points at the leading cell edge. |
bottom |
float | None
|
Optional nonnegative points below content. |
end |
float | None
|
Optional nonnegative points at the trailing cell edge. Omitted sides are not authored; zero explicitly removes that padding. |
CharacterStyleDefinition
dataclass
Named character style using the same properties as TextRun formatting.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Style name; existing character styles are updated in place. |
base_style |
str | None
|
Character parent name/ID, creation-only; forward links work. |
linked_style |
str | None
|
Optional paragraph-style name/ID to pair with. Writes only this style's link, not a reciprocal link or inherited formatting. |
font |
str | None
|
Optional Latin font name. |
size |
float | None
|
Optional font size in points (not font_size). |
bold |
bool | None
|
Optional bold style toggle. |
italic |
bool | None
|
Optional italic style toggle. |
underline |
bool | str | None
|
Optional bool or supported underline style. |
color |
tuple[int, int, int] | str | dict | None
|
Optional RGB, auto or supported theme color value. |
superscript |
bool | None
|
Optional superscript request. |
subscript |
bool | None
|
Optional subscript request. |
strike |
bool | None
|
Optional strikethrough toggle. |
all_caps |
bool | None
|
Optional capitals toggle. |
small_caps |
bool | None
|
Optional small capitals toggle. |
language |
RunLanguage | None
|
Optional RunLanguage hints. |
bold_complex_script |
bool | None
|
Optional complex-script bold toggle. |
italic_complex_script |
bool | None
|
Optional complex-script italic toggle. |
size_complex_script |
float | None
|
Optional complex-script size in points. |
rtl |
bool | None
|
Optional RTL run request. |
complex_script |
bool | None
|
Optional complex-script selection request. |
font_east_asia |
str | None
|
Optional East Asian literal font name. |
font_complex_script |
str | None
|
Optional complex-script literal font name. |
ColumnChartRun
dataclass
Bases: Component
One inline series in a body paragraph.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
float
|
Positive width in points. |
height |
float
|
Positive height in points. |
categories |
list[str]
|
Nonempty ordered list of labels. |
values |
list[float]
|
One finite number per label, in the same order. |
Comment
dataclass
Bases: Component
Structured content for a body-anchored base-schema comment range.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
object
|
Paragraph/table content; may be deferred. |
author |
str | None
|
Optional author; absent/empty falls back to document comment_author. |
date |
str | None
|
Optional YYYY-MM-DDTHH:MM:SSZ timestamp; absent uses snapshot time. |
initials |
str | None
|
Optional initials; no threaded-comment extension metadata is generated. |
ContentControlMetadata
dataclass
Metadata for a rich-text row or cell content control.
Deferred
Bases: Generic[_T]
A lazy computation memoized for this handle's lifetime.
Awaiters share the producer; cancelling one awaiter leaves the others intact. Use cancel() to explicitly cancel this externally owned computation.
DeferredProperty
Bases: Generic[_T]
A per-pass reference to a declared field, not a memoized computation.
DocumentDefaults
dataclass
Merge explicit defaults without materializing formatting in content.
Attributes:
| Name | Type | Description |
|---|---|---|
run |
RunDefaults | None
|
Run-default overrides, or None to preserve template defaults. |
paragraph |
ParagraphDefaults | None
|
Paragraph-default overrides, or None to preserve templates. All fields support the generic deferred-value mechanism. |
DocumentGrid
dataclass
Section grid pitch. Lines use twips and character deltas use 1/4096 points.
Field
dataclass
Bases: Component
A paragraph-local balanced field with independently deferred properties.
Attributes:
| Name | Type | Description |
|---|---|---|
instruction |
FieldInstruction
|
FieldInstruction, optionally deferred. |
children |
object
|
Cached rich inlines, optionally deferred. Nested fields are legal; range markers and fields inside hyperlinks are unsupported. |
form |
str
|
simple (default) or complex begin/instruction/separate/result/end. |
dirty |
bool | None
|
Optional consumer-update request, not library-side evaluation. |
locked |
bool | None
|
Optional field lock; absent/false/true remain distinct. |
FieldInstruction
dataclass
Bases: Component
Typed common instructions or an explicit unparsed escape hatch.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
page, num_pages, reference, table_of_contents, or raw. |
name |
str | None
|
Bookmark name for a reference; checked against generated/imported names. |
code |
str | None
|
Raw instruction text, preserved verbatim without interpreting targets. |
num_pages()
classmethod
Request NUMPAGES without calculating pagination.
page()
classmethod
Request a PAGE instruction, not a calculated page number.
raw(code)
classmethod
Preserve nonempty XML instruction text without parsing field syntax.
reference(name)
classmethod
Request a REF to a checked bookmark name.
table_of_contents()
classmethod
Request a heading-level 1–3 TOC; cached content remains caller-supplied.
Footer
dataclass
Bases: Component
A section footer.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
BlockChildren | Callable[[], BlockChildren] | None
|
List of Paragraph or Table components, or coroutines that
resolve to these types. May be a zero-argument callable for lazy
evaluation (useful with |
Header
dataclass
Bases: Component
A section header.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
BlockChildren | Callable[[], BlockChildren] | None
|
List of Paragraph or Table components, or coroutines that
resolve to these types. May be a zero-argument callable for lazy
evaluation (useful with |
Hyperlink
dataclass
Bases: Component
An external absolute URI/IRI or explicit internal BookmarkTarget.
Attributes:
| Name | Type | Description |
|---|---|---|
target |
str | BookmarkTarget | Awaitable[str | BookmarkTarget] | Callable[[], str | BookmarkTarget | Awaitable[str | BookmarkTarget]]
|
Absolute external URI/IRI or BookmarkTarget, optionally deferred. |
children |
Sequence[InlineElement] | Awaitable[Sequence[InlineElement]] | Callable[[], Sequence[InlineElement] | Awaitable[Sequence[InlineElement]]]
|
TextRun/ImageRun/Tab/Break display children or deferred sequence. Nested hyperlinks are deliberately unsupported (not an XSD restriction). |
tooltip |
str | Awaitable[str] | Callable[[], str | Awaitable[str]] | None
|
Optional hover text, resolved independently of the target. |
history |
bool | Awaitable[bool] | Callable[[], bool | Awaitable[bool]] | None
|
Optional Word visited-history flag; does not fetch the target. |
ImageAnchor
dataclass
Floating picture or shape placement. Offsets and wrap distances use points.
ImageCrop
dataclass
Physical crop insets in percent of the original picture dimensions.
ImageRun
dataclass
Bases: Component
An image embedded in the document.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
bytes | str | Path | Coroutine[None, None, bytes]
|
Image data as bytes, file path, or a coroutine that resolves to bytes. |
type |
str | None
|
Image type (e.g., 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'svg'). |
transformation |
dict[Literal['width', 'height', 'rotation', 'crop', 'anchor', 'flip_horizontal', 'flip_vertical'], int | float | bool | ImageCrop | ImageAnchor] | None
|
Optional width and height in points, rotation in degrees, crop and anchor. |
alt_text |
dict[Literal['title', 'description', 'name'], str] | None
|
Alternative text for accessibility. |
InlineContentControl
dataclass
Bases: Component
Rich-text control for inline runs in a paragraph.
InlineFraction
dataclass
Bases: Component
A stacked fraction in a body paragraph, including body table cells.
Both operands are nonempty single-line literal text and can be deferred.
LineHeight
dataclass
A line-height request, not a computed or effective layout measurement.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
multiple, exact, or at_least. |
value |
float
|
Nonnegative finite multiple or point value, according to rule. Wire conversion rounds to 1/240 line or one twip respectively. |
at_least(points)
classmethod
Specify a minimum height in points; consumers may expand it.
exact(points)
classmethod
Specify an exact height in points (which may clip tall content).
multiple(value)
classmethod
Specify a multiple of the consumer's single-line height.
LineNumbering
dataclass
Section line numbering. Distance uses twips.
Note
dataclass
Bases: Component
A footnote/endnote definition, with independently deferred fields.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
'footnote' or 'endnote'; each has its own ID namespace. |
id |
int
|
Nonnegative 32-bit ordinary-note identity, including zero. |
children |
object
|
Block content; may be deferred. Special separators are not ordinary notes. |
endnote(id, children)
classmethod
Create an ordinary endnote definition.
footnote(id, children)
classmethod
Create an ordinary footnote definition.
NoteNumbering
dataclass
Document-wide start and restart policy for one kind of note.
NoteReference
dataclass
Bases: Component
An ordinary-note reference in the body, never expanded by the renderer.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
'footnote' or 'endnote', optionally deferred. |
id |
int
|
Referenced ordinary-note ID, optionally deferred. |
endnote(id)
classmethod
Reference an ordinary endnote.
footnote(id)
classmethod
Reference an ordinary footnote.
NumberingDefinition
dataclass
An explicit concrete list definition using the current abstract subset.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
int
|
Explicit nonnegative 32-bit concrete identity; imported collisions fail. |
levels |
list[NumberingLevel]
|
Unique abstract level definitions in 0..8. |
abstract_id |
int | None
|
Optional nonnegative 32-bit abstract identity. Definitions sharing an identity provide identical ordered levels. Imported IDs are reserved. None allocates a private abstract identity. |
inherit_style |
str | None
|
Optional authored numbering style name or ID; omit levels and concrete overrides when inheriting. |
start_overrides |
list[NumberingStartOverride]
|
Optional concrete start overrides at defined levels. Fields support the existing generic deferred interpreter. |
level_overrides |
list[NumberingLevel]
|
Optional NumberingLevel replacements at unique defined levels. May coexist with start_overrides on the same level; the two requests serialize together without computing effective counters. |
NumberingLevel
dataclass
A numbering level request; displayed labels are computed by the consumer.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
int
|
Level index in 0..8. |
start |
int
|
Nonnegative starting value. |
format |
str
|
Numbering format token. |
text |
str
|
Label pattern using level placeholders. |
is_legal |
bool | None
|
Optional decimal-display request for all referenced levels. None omits isLgl; false and true emit explicit requests. Does not change format. Supports generic deferred values. |
suffix |
str | None
|
Optional tab, space, or nothing separator request. None omits suff (the consumer defaults to tab); no text is inserted by the library. Supports generic deferred values. |
restart |
int | None
|
Optional nonnegative 32-bit one-based restart trigger; zero requests never restarting. None omits lvlRestart. Values ignored by the consumer are preserved; no counters are calculated. Supports generic deferred values. |
alignment |
str | None
|
Optional left, center, right, start, or end label alignment. Distinct from paragraph text alignment. None omits lvlJc and retains consumer direction-dependent defaults. Supports deferred values. |
label_format |
RunDefaults | None
|
Direct run formatting for the generated numbering label. |
paragraph_format |
ParagraphDefaults | None
|
Level paragraph properties with indents in points. |
paragraph_style |
str | None
|
Optional registered paragraph style name or ID. |
NumberingStartOverride
dataclass
A concrete list's start override, without computing displayed labels.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
int
|
A unique level defined by the numbering definition (0..8). |
start |
int
|
Nonnegative 32-bit start, including zero. |
NumberingStyleDefinition
dataclass
Name an authored list definition through a concrete numbering ID.
PageBorder
dataclass
A physical page-edge line border. Size is in eighth-points and space in points.
Paragraph
dataclass
Bases: Component
A paragraph with optional formatting and child runs.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
Awaitable[str] | Callable[[], Awaitable[str] | str] | str | None
|
Shorthand for a paragraph with a single text run. May be a
zero-argument callable for lazy evaluation (useful with
|
comment_text |
Awaitable[str] | str | None
|
Text content for a Word comment attached to this paragraph. |
comment_author |
Awaitable[str] | str | None
|
Author name for the comment. Overrides the document-level default. |
children |
InlineChildren | Callable[[], InlineChildren] | None
|
List of TextRun, ImageRun, Tab, Break, Hyperlink, or coroutines
that resolve to these types. May be a zero-argument callable for
lazy evaluation (useful with |
heading |
int | None
|
Heading level. |
style |
str | None
|
Style name to apply. |
alignment |
WD_PARAGRAPH_ALIGNMENT | None
|
Paragraph alignment. |
spacing_before |
int | None
|
Space before paragraph in points. |
spacing_after |
int | None
|
Space after paragraph in points. |
line_spacing |
float | None
|
Line spacing multiplier. |
line_height |
LineHeight | None
|
Typed multiple/exact/minimum line height. Mutually exclusive with line_spacing; accepts the same generic deferred inputs. |
tab_stops |
list[TabStop]
|
Local custom tab overrides in points; empty leaves inherited stops unchanged. Supports generic deferred inputs. |
bidi |
bool | None
|
Optional paragraph RTL layout request, independent of run RTL and stored text order. Supports generic deferred inputs. |
left_indent |
int | None
|
Left indent in points. |
right_indent |
int | None
|
Right indent in points. |
first_line_indent |
int | None
|
First line indent in points. |
keep_together |
bool | None
|
Keep all lines of paragraph on same page. |
keep_with_next |
bool | None
|
Keep paragraph with next paragraph. |
page_break_before |
bool | None
|
Start paragraph on new page. |
suppress_line_numbers |
bool | None
|
Optional line-number suppression. |
widow_control |
bool | None
|
Enable widow/orphan control. |
__post_init__()
Validate that either text or children is provided, not both.
Raises:
| Type | Description |
|---|---|
ValueError
|
If both text and children are provided, or neither is provided. |
ParagraphDefaults
dataclass
Paragraph defaults using points for lengths, not paragraph-style inches.
Attributes:
| Name | Type | Description |
|---|---|---|
alignment |
str | int | None
|
Optional left/center/right/justify request. |
spacing_before |
float | None
|
Space before in points, including explicit zero. |
spacing_after |
float | None
|
Space after in points, including explicit zero. |
line_spacing |
float | None
|
Legacy line-height multiplier, exclusive with line_height. |
line_height |
LineHeight | None
|
Optional typed line-height request. |
tab_stops |
list[TabStop]
|
Nonempty list replaces template defaults' local tabs; empty preserves them. Positions use signed points. |
left_indent |
float | None
|
Left indent in points. |
right_indent |
float | None
|
Right indent in points. |
first_line_indent |
float | None
|
Signed points; negative means hanging. Explicit values remove the conflicting template first-line/hanging attribute. |
keep_together |
bool | None
|
Optional keep-lines request. |
keep_with_next |
bool | None
|
Optional keep-next request. |
page_break_before |
bool | None
|
Optional page-break request. |
suppress_line_numbers |
bool | None
|
Optional line-number suppression. |
widow_control |
bool | None
|
Optional widow/orphan control. |
bidi |
bool | None
|
Optional paragraph direction, independent of run RTL. |
ParagraphStyleDefinition
dataclass
Definition of a named paragraph style.
If a style with name already exists in the document it will be modified
in place; otherwise a new style is created.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The style name. If a style with this name already exists in the document it will be modified in place; otherwise a new style is created. |
base_style |
str | None
|
Name of the style to inherit from. Only applied when creating a new style. |
next_paragraph_style |
str | None
|
Name of the style to apply to the next paragraph. |
linked_style |
str | None
|
Optional character-style name/ID to pair with. Forward and deferred values work; omission preserves existing links. No automatic reciprocal link or effective formatting is produced. |
font |
str | None
|
Font name. |
font_size |
int | None
|
Font size in points. |
bold |
bool | None
|
Apply bold formatting. |
italic |
bool | None
|
Apply italic formatting. |
underline |
bool | None
|
Apply underline formatting. |
color |
tuple[int, int, int] | None
|
Font color as (R, G, B) tuple (0-255). |
alignment |
WD_PARAGRAPH_ALIGNMENT | None
|
Paragraph alignment. |
spacing_before |
int | None
|
Space before paragraph in points. |
spacing_after |
int | None
|
Space after paragraph in points. |
line_spacing |
float | None
|
Line spacing multiplier. |
line_height |
LineHeight | None
|
Typed multiple/exact/minimum line height, mutually exclusive with line_spacing. Exact and minimum values are points. |
tab_stops |
list[TabStop]
|
Local custom tab overrides in points; inherited stops are additive. Use clear stops to remove known inherited positions. |
language |
RunLanguage | None
|
Optional RunLanguage hints, without registry validation. |
bold_complex_script |
bool | None
|
Optional complex-script bold style toggle. |
italic_complex_script |
bool | None
|
Optional complex-script italic style toggle. |
size_complex_script |
float | None
|
Optional complex-script size in points. |
rtl |
bool | None
|
Optional right-to-left run request. |
complex_script |
bool | None
|
Optional request to use complex-script formatting. |
bidi |
bool | None
|
Optional paragraph RTL layout request (separate from run rtl). |
font_east_asia |
str | None
|
Optional literal East Asian font name. |
font_complex_script |
str | None
|
Optional literal complex-script font name. |
left_indent |
float | None
|
Left indent in inches. |
right_indent |
float | None
|
Right indent in inches. |
first_line_indent |
float | None
|
First line indent in inches. |
keep_together |
bool | None
|
Keep all lines of paragraph on same page. |
keep_with_next |
bool | None
|
Keep paragraph with next paragraph. |
page_break_before |
bool | None
|
Start paragraph on new page. |
suppress_line_numbers |
bool | None
|
Optional line-number suppression. |
widow_control |
bool | None
|
Enable widow/orphan control. |
RangeEnd
dataclass
Bases: Component
The end of a preceding start with the same stable id in the same story.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The paired RangeStart's authoring key; may be deferred. |
bookmark(name)
classmethod
Pair with RangeStart.bookmark(name).
RangeStart
dataclass
Bases: Component
A range's start; ranges may overlap and span paragraphs in one story.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Stable authoring key, distinct from allocated XML IDs. |
kind |
str
|
'bookmark' or 'comment'. |
name |
str | None
|
Bookmark name for a bookmark range. |
text |
str | None
|
Comment text for a comment range. |
author |
str | None
|
Optional comment author. |
bookmark(name)
classmethod
Create a named bookmark start; pair with RangeEnd.bookmark(name).
comment(id, text, author=None)
classmethod
Create a body-comment start with an explicit stable identity.
structured_comment(id, content)
classmethod
Pair a structured Comment's content with RangeEnd(id).
RowHeight
dataclass
An exact or minimum table row height, not a calculated row size.
Attributes:
| Name | Type | Description |
|---|---|---|
rule |
str
|
exact or at_least. |
value |
float
|
Nonnegative finite points, rounded to the nearest twip. |
at_least(points)
classmethod
Request a minimum height; consumers may expand it for content.
exact(points)
classmethod
Request an exact height; content may be clipped by consumers.
RunDefaults
dataclass
Run property overrides in document defaults; omitted fields retain templates.
Attributes:
| Name | Type | Description |
|---|---|---|
font |
str | None
|
Literal Latin font name. |
size |
float | None
|
Nonnegative finite size in points. |
bold |
bool | None
|
Optional bold request. |
italic |
bool | None
|
Optional italic request. |
underline |
bool | str | None
|
Optional boolean or supported underline style. |
color |
tuple[int, int, int] | str | dict | None
|
Optional RGB, auto or theme color. |
superscript |
bool | None
|
Optional superscript request. |
subscript |
bool | None
|
Optional subscript request. |
strike |
bool | None
|
Optional strikethrough request. |
all_caps |
bool | None
|
Optional capitals request. |
small_caps |
bool | None
|
Optional small capitals request. |
language |
RunLanguage | None
|
Language hints, without registry validation. |
bold_complex_script |
bool | None
|
Optional complex-script bold request. |
italic_complex_script |
bool | None
|
Optional complex-script italic request. |
size_complex_script |
float | None
|
Complex-script size in points. |
rtl |
bool | None
|
Optional RTL run request. |
complex_script |
bool | None
|
Optional complex-script selection request. |
font_east_asia |
str | None
|
Literal East Asian font name. |
font_complex_script |
str | None
|
Literal complex-script font name. |
RunLanguage
dataclass
Unparsed language hints; no registry lookup, proofing or shaping occurs.
Attributes:
| Name | Type | Description |
|---|---|---|
latin |
str | None
|
Optional default language string (w:val). |
east_asia |
str | None
|
Optional East Asian language string (w:eastAsia). |
bidi |
str | None
|
Optional complex-script language string (w:bidi). Strings are preserved, not normalized or checked against BCP 47. |
Section
dataclass
Bases: Component
A document section with optional headers and footers.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
BlockChildren | Callable[[], BlockChildren] | None
|
List of Paragraph or Table components, or coroutines that
resolve to these types. May be a zero-argument callable for lazy
evaluation (useful with |
properties |
SectionProperties | None
|
Section configuration. |
headers |
dict[HeaderFooterType, Header] | None
|
Dictionary mapping header types ('default', 'first', 'even') to Header components. |
footers |
dict[HeaderFooterType, Footer] | None
|
Dictionary mapping footer types ('default', 'first', 'even') to Footer components. |
SectionProperties
dataclass
Configuration for a document section.
Attributes:
| Name | Type | Description |
|---|---|---|
page_size |
dict[Literal['width', 'height'], int] | None
|
Page dimensions. |
page_orientation |
Literal['portrait', 'landscape'] | None
|
'portrait' or 'landscape'. |
page_margins |
dict[Literal['top', 'bottom', 'left', 'right', 'header', 'footer'], int] | None
|
Page margin sizes. Keys are 'top', 'bottom', 'left', 'right'; values are in EMU (English Metric Units). All keys are optional. |
page_numbering |
dict[Literal['start', 'format'], int | str] | None
|
Page numbering configuration. |
line_numbering |
LineNumbering | None
|
Optional section line-numbering settings. |
columns |
dict[Literal['count', 'space', 'separator'], int | bool] | None
|
Column configuration (dict with 'count', 'space', 'separator'). |
vertical_align |
Literal['top', 'center', 'bottom', 'both'] | None
|
Vertical alignment ('top', 'center', 'bottom', 'both'). |
title_page |
bool | None
|
Use different header/footer on first page. |
type |
Literal['nextPage', 'nextColumn', 'continuous', 'evenPage', 'oddPage'] | None
|
Section break type ('nextPage', 'nextColumn', 'continuous', 'evenPage', 'oddPage'). |
bidi |
bool | None
|
Optional right-to-left section page direction request, separate from paragraph bidi and run RTL. Omission preserves inherited or template section properties; false explicitly requests LTR. |
rtl_gutter |
bool | None
|
Optional right-side gutter placement request, independent of section/text bidi. Omission preserves template/previous settings; false explicitly disables the request. No gutter size, margin mirroring or page layout is computed. |
ShapeRun
dataclass
Bases: Component
Geometric shape or standalone plain DrawingML text box.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
float
|
Positive width in points, within DrawingML coordinate bounds. |
height |
float
|
Positive height in points, within DrawingML coordinate bounds. |
geometry |
Literal['rectangle', 'ellipse', 'text_box']
|
Rectangle, ellipse or text_box. Text boxes have no geometric fill/outline and use their own text transform rather than useSpRect. |
fill |
tuple[int, int, int] | None
|
Optional RGB geometric fill; not supported for text_box. |
text |
str | None
|
Optional plain multiline text. None omits geometric-shape text; a text_box still creates one empty text paragraph. |
outline |
ShapeOutline | None
|
Optional geometric line; not supported for text_box. |
text_format |
ShapeTextFormat | None
|
Optional uniform text requests, shared by both modes. |
anchor |
ImageAnchor | None
|
Optional floating position and wrapping. None keeps the shape inline. |
ShapeTextFormat
dataclass
Uniform DrawingML text requests; None preserves consumer defaults.
Attributes:
| Name | Type | Description |
|---|---|---|
font_size |
float | None
|
Points in 1..4000, rounded to hundredths of a point. |
bold |
bool | None
|
Explicit true/false, independent of surrounding paragraph text. |
color |
tuple[int, int, int] | None
|
RGB text color, independent of the shape fill and outline. |
alignment |
Literal['left', 'center', 'right'] | None
|
Left, center or right for each shape-text paragraph. |
vertical_alignment |
Literal['top', 'center', 'bottom'] | None
|
Top, center or bottom within the shape text body. |
italic |
bool | None
|
Explicit true/false; None omits the request. |
font |
str | None
|
Latin typeface request; no installed-font lookup or embedding. |
Tab
dataclass
Bases: Component
A tab character.
TabStop
dataclass
A local custom tab override, not a computed effective paragraph tab.
Attributes:
| Name | Type | Description |
|---|---|---|
position |
float
|
Signed points relative to the paragraph's leading text margin; rounded to twips. Positions must be unique after rounding. |
alignment |
str
|
left, center, right, decimal, bar, clear, start, or end. |
leader |
str | None
|
Optional none, dot, hyphen, underscore, heavy, or middle_dot. Clear and bar stops do not advance text or generate a leader. |
Table
dataclass
Bases: Component
A table with rows and cells.
Attributes:
| Name | Type | Description |
|---|---|---|
rows |
MutableSequence[TableRow | Coroutine[None, None, TableRow]] | Callable[[], MutableSequence[TableRow | Coroutine[None, None, TableRow]]]
|
List of TableRow components or coroutines that resolve to rows.
May be a zero-argument callable for lazy evaluation (useful with
|
column_widths |
Sequence[int] | None
|
List of column widths in twips (DXA). 1440 twips equals 1 inch; approximately 567 twips equals 1cm. Setting this implies fixed layout (autofit is disabled automatically). |
layout |
Literal['autofit', 'fixed'] | None
|
Table layout type. |
style |
str | None
|
Table style name. |
borders |
MutableSequence[TableBorder] | None
|
Cell border configuration. |
look |
TableLook | None
|
Optional TableLook activation requests. Missing fields retain the library defaults; no effective conditional formatting is computed. |
alignment |
str | None
|
Optional left, center, right, start, or end inline-table alignment request. None retains style/consumer defaults. Independent of paragraph/cell alignment; supports generic deferred fields. |
TableBorder
dataclass
Defines a table border.
Attributes:
| Name | Type | Description |
|---|---|---|
side |
Literal['top', 'left', 'bottom', 'right', 'insideH', 'insideV']
|
The side of the cell for the border. |
val |
Literal['single']
|
The type of border; only single is currently supported. |
sz |
int
|
Size of the border. |
color |
tuple[int, int, int]
|
Color of the border (RGB); 0-255. |
hex_color
property
Color as hexadecimal.
TableCell
dataclass
Bases: Component
A table cell containing paragraphs or nested tables.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
BlockChildren | Callable[[], BlockChildren] | None
|
List of paragraph, table or block control components, or coroutines that
resolve to these types. May be a zero-argument callable for lazy
evaluation (useful with |
grid_span |
int | None
|
Number of columns this cell spans (horizontal merge). Defaults to None (no spanning). |
vmerge |
Literal['restart', 'continue'] | None
|
Vertical merge role. |
borders |
MutableSequence[CellBorder] | None
|
Per-side border definitions for this cell. Defaults to None. |
background_color |
tuple[int, int, int] | None
|
RGB background fill colour for the cell as a
|
vertical_alignment |
Literal['top', 'center', 'bottom'] | None
|
Vertical alignment of content within the cell.
|
margins |
CellMargins | None
|
Optional CellMargins in points; accepts generic deferred inputs. |
text_direction |
str | None
|
Optional checked lrTb/tbRl/btLr/lrTbV/tbRlV/tbLrV text flow, independent of paragraph bidi; accepts generic deferred inputs. |
TableLook
dataclass
Conditional table-style activation, independent of direct cell formatting.
Attributes:
| Name | Type | Description |
|---|---|---|
first_row |
bool | None
|
Optional first-row formatting request; defaults to true. |
last_row |
bool | None
|
Optional last-row request; defaults to false. |
first_column |
bool | None
|
Optional first-column request; defaults to true. |
last_column |
bool | None
|
Optional last-column request; defaults to false. |
horizontal_banding |
bool | None
|
Optional row-banding request; defaults to true. |
vertical_banding |
bool | None
|
Optional column-banding request; defaults to false. Defaults here are existing library policy, not the normative default for omitted tblLook. Each field supports generic deferred inputs. |
TableRow
dataclass
Bases: Component
A table row containing cells.
Attributes:
| Name | Type | Description |
|---|---|---|
children |
MutableSequence[TableCell | Coroutine[None, None, TableCell]] | Callable[[], MutableSequence[TableCell | Coroutine[None, None, TableCell]]]
|
List of TableCell components or coroutines that resolve to
cells. May be a zero-argument callable for lazy evaluation (useful
with |
height |
RowHeight | None
|
Optional exact/minimum RowHeight in points. |
repeat_header |
bool | None
|
Optional header repetition request. Only a contiguous leading group of header rows repeats in consuming applications. |
cant_split |
bool | None
|
Optional request to keep the row on one page if it fits. All three properties support generic deferred inputs. |
TableSectionFormat
dataclass
Formatting options for a section of a table style.
Attributes:
| Name | Type | Description |
|---|---|---|
font |
str | None
|
Font name. |
font_size |
int | None
|
Font size in points. |
bold |
bool | None
|
Apply bold formatting. |
italic |
bool | None
|
Apply italic formatting. |
underline |
bool | None
|
Apply underline formatting. |
color |
tuple[int, int, int] | None
|
Font color as (R, G, B) tuple (0-255). |
background |
tuple[int, int, int] | None
|
Cell shading fill color as (R, G, B) tuple (0-255). |
alignment |
WD_PARAGRAPH_ALIGNMENT | None
|
Paragraph alignment. |
spacing_before |
int | None
|
Space before paragraph in points. |
spacing_after |
int | None
|
Space after paragraph in points. |
line_height |
LineHeight | None
|
Optional typed paragraph line-height request. |
tab_stops |
list[TabStop]
|
Custom paragraph tab overrides in points; empty does not clear inherited stops. Explicit clear stops remove known positions. |
bidi |
bool | None
|
Optional paragraph direction request, not section/run direction. These fields support generic deferred inputs; no effective conditional formatting or layout is calculated. |
language |
RunLanguage | None
|
Optional RunLanguage hints, without registry validation. |
bold_complex_script |
bool | None
|
Optional complex-script bold style toggle. |
italic_complex_script |
bool | None
|
Optional complex-script italic style toggle. |
size_complex_script |
float | None
|
Optional complex-script size in points. |
rtl |
bool | None
|
Optional RTL run request, separate from paragraph bidi. |
complex_script |
bool | None
|
Optional request to use complex-script formatting. |
font_east_asia |
str | None
|
Optional literal East Asian font name. |
font_complex_script |
str | None
|
Optional literal complex-script font name. |
TableStyleDefinition
dataclass
Definition of a named table style with per-section formatting.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The style name. |
base_style |
str | None
|
Name of the style to inherit from. |
whole_table |
TableSectionFormat | None
|
Formatting applied to all cells. |
first_row |
TableSectionFormat | None
|
Header row formatting. |
last_row |
TableSectionFormat | None
|
Footer row formatting. |
first_column |
TableSectionFormat | None
|
First column formatting. |
last_column |
TableSectionFormat | None
|
Last column formatting. |
banding_1_row |
TableSectionFormat | None
|
Alternating row stripe 1 formatting. |
banding_2_row |
TableSectionFormat | None
|
Alternating row stripe 2 formatting. |
banding_1_column |
TableSectionFormat | None
|
Alternating column stripe 1 formatting. |
banding_2_column |
TableSectionFormat | None
|
Alternating column stripe 2 formatting. |
top_left_cell |
TableSectionFormat | None
|
Top-left corner cell formatting (nwCell). |
top_right_cell |
TableSectionFormat | None
|
Top-right corner cell formatting (neCell). |
bottom_left_cell |
TableSectionFormat | None
|
Bottom-left corner cell formatting (swCell). |
bottom_right_cell |
TableSectionFormat | None
|
Bottom-right corner cell formatting (seCell). |
Note
Unlike ParagraphStyleDefinition, this always creates a new style.
A ValueError is raised if a style with the given name already
exists in the document.
TextRevision
dataclass
Metadata for an authored insertion or deletion of one text run.
TextRun
dataclass
Bases: Component
A run of text with formatting.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
Awaitable[str] | Callable[[], Awaitable[str] | str] | str
|
The text content. May be a zero-argument callable for lazy
evaluation (useful with |
comment_text |
Awaitable[str] | str | None
|
Text content for a Word comment attached to this run. |
comment_author |
Awaitable[str] | str | None
|
Author name for the comment. Overrides the document-level default. |
bold |
bool | None
|
Apply bold formatting. |
italic |
bool | None
|
Apply italic formatting. |
underline |
bool | str | None
|
Apply underline formatting. |
font |
str | None
|
Font name. |
size |
int | None
|
Font size in points. |
color |
tuple[int, int, int] | str | dict | None
|
Text color as (R, G, B) tuple (0-255). |
superscript |
bool | None
|
Apply superscript formatting. |
subscript |
bool | None
|
Apply subscript formatting. |
strike |
bool | None
|
Apply strikethrough formatting. |
all_caps |
bool | None
|
Apply all caps formatting. |
small_caps |
bool | None
|
Apply small caps formatting. |
language |
RunLanguage | None
|
Optional RunLanguage hints, without registry validation. |
bold_complex_script |
bool | None
|
Optional independent complex-script bold request. |
italic_complex_script |
bool | None
|
Optional independent complex-script italic request. |
size_complex_script |
float | None
|
Optional complex-script size in points. |
rtl |
bool | None
|
Optional right-to-left run request; does not reverse stored text. |
complex_script |
bool | None
|
Optional request to use complex-script formatting. These fields accept generic deferred inputs. |
font_east_asia |
str | None
|
Optional literal East Asian font name. |
font_complex_script |
str | None
|
Optional literal complex-script font name. |
style |
str | None
|
Optional character style name/ID; direct properties remain separate. |
rocx.options
Explicit rendering policy; these immutable options do not contain producers.
ReadLimits
dataclass
Application package-read budgets, not OOXML schema limits.
RenderOptions
dataclass
Rendering profile, optional timestamp override and template-read budgets.
Only the Transitional profile is implemented. Strict is explicitly rejected. Omitting timestamp preserves the timestamp already captured in the snapshot.
Imported DOCX editor
rocx.editor.ImportedDocument.open(data) opens an immutable snapshot. For
example, on a fixture whose first body block is a plain paragraph starting
with “Draft”, replace that word and set the package's existing core title
in one transaction:
from rocx.editor import ImportedDocument, ResourceEdit, TextInsertion, TextRangeEdit
doc = ImportedDocument.open(data)
first = doc.body[0]
preview = doc.preview(
[],
text_ranges=[TextRangeEdit(first.anchor, 0, 5, "Final")],
text_insertions=[TextInsertion(first.anchor, 5, " copy")],
resources=[ResourceEdit.core_title("Annual report")],
)
copy_bytes = preview.to_docx()
[0, 5) counts Unicode scalar values in the original paragraph. The
replacement keeps the first selected character's formatting. The insertion at
original position 5 follows the replacement, producing “Final copy”. Reopen
copy_bytes to obtain anchors for the new document; doc and its anchors
remain usable. See the cross-binding editor reference
for the other batch fields and separate story and revision calls.
Use doc.metadata_field("creator") and doc.custom_property("Approved") to
read core/extended text and named string or boolean properties. Missing
properties return None. Pass ResourceEdit.metadata("manager", "Review lead")
or ResourceEdit.custom_property("Approved", False) in resources; use
None to clear either property.