DOCX compatibility
rocx writes Transitional DOCX. It does not paginate, render pages or calculate fields, counters or effective styles. See viewer compatibility for LibreOffice results. Desktop Word has not been verified.
Implemented surface
| Area | Supported |
|---|---|
| Text and layout | Unicode, whitespace, empty runs, tabs, breaks, run/paragraph formatting, columns, page settings and default/first/even headers and footers. Formatting |
| Resources | Document defaults, paragraph/character/table/numbering styles, list levels and concrete overrides. Styles · Numbering |
| Tables | Nested tables, fixed/autofit widths, spans, vertical merges, borders, shading, alignment, row pagination requests and conditional regions. Tables |
| References | Links, overlapping bookmarks and body-comment ranges, structured comments, footnotes, endnotes, simple and complex fields with cached results. Ranges · Notes · Fields |
| Drawings | Inline or anchored PNG/JPEG/GIF/BMP/TIFF with density-aware dimensions and alt text; rectangles, ellipses, plain text boxes, single-series column charts and literal inline fractions. Drawings and restrictions |
| Review and forms | Tracked text insertions, deletions and paired moves; inline/block controls and row/cell wrappers; tagged plain-text replacement. Revisions · Content controls |
| Metadata | Core properties, snapshot timestamp, company, manager and custom document properties. |
Rust and Python examples use their respective public APIs. For the available JavaScript factories, templates, inspection and edit previews, see the Node/browser package guide. Preserving an imported feature does not mean it is editable.
Hyperlinks: use absolute URI/IRI targets for external links and explicit bookmark targets for internal ones. External targets preserve Unicode, escapes, queries and fragments; invalid percent escapes, whitespace, controls and forbidden URI characters fail. This checks syntax, not safety. rocx never fetches targets. Format display runs explicitly; links are not automatically blue or underlined. Nested links are unsupported.
Units and defaults
| Setting | Unit |
|---|---|
| Run size, paragraph spacing/direct indents, image dimensions | Points |
| Paragraph style left/right/first-line indent | Inches |
| Section page sizes and margins | EMUs (914,400/inch) |
| Table widths and column spacing | Twips (1,440/inch) |
| Border size | Eighth-points |
line_spacing |
Multiplier |
Rust provides checked Points, Twips, Emu and HalfPoints conversions. The blank template uses an 8.5 × 11 inch page with 1.25 inch left/right margins.
Document properties
from rocx import declarative as d
document = d.Document([], title="Annual report", company="Atlas", manager="Ada",
custom_properties={"Project": "Atlas", "Approved": False})
In Rust, use Metadata::with_company, with_manager, with_custom_properties (strings) and with_custom_boolean_properties. Custom names must be nonblank and match exactly. Omit a property to keep its template value; "" sets empty text rather than deleting it. Updating a linked, ambiguous or differently typed custom property fails.
Resolution, editing and output
| Imported DOCX operation | Rust | Python | JavaScript |
|---|---|---|---|
| Combine ordinary edits atomically (all batch fields) | doc.preview_edits(EditBatch { .. }) |
doc.preview(alignments, ...) |
doc.preview(batch) |
| Inspect footnotes, endnotes and comments | doc.entry_stories()? |
doc.entry_stories |
doc.entryStories() |
| Inspect the styles part and direct style metadata | doc.styles()? |
doc.styles |
doc.styles() |
| Inspect direct body control metadata | BodyBlock::ContentControl |
BodyContentControl |
kind: "contentControl" |
| Inspect block/inline/row/cell controls and their physical anchors | doc.controls() |
doc.controls |
doc.controls() |
| Discover wrapping sites; wrap / replace / unwrap single-text controls | control_sites, preview_wrap_control, preview_replace_control, preview_unwrap_control |
Same spellings, control_sites is a property |
controlSites, previewWrapControl, previewReplaceControl, previewUnwrapControl |
| Select a drop-down value or replace the choices and selection | preview_control_choice |
preview_control_choice |
previewControlChoice |
| Patch an eligible control's alias, tag or single-text value | ControlEdit / preview_with_controls |
ControlEdit / preview([], controls=[edit]) |
preview({controls: [edit]}) |
| Inspect an inline insertion/deletion | ImportedInlineNode::Revision |
ImportedRevision |
kind: "revision" |
| Track a direct body text edit / paired move | preview_tracked_text / preview_tracked_move |
preview_tracked_text / preview_tracked_move |
previewTrackedText / previewTrackedMove |
| Track direct bold / inspect the pending property change on a run | preview_tracked_bold / property_revision |
preview_tracked_bold / property_revision |
previewTrackedBold / propertyRevision |
| Track / review a whole direct body paragraph | preview_tracked_paragraph / preview_paragraph_revision |
preview_tracked_paragraph / preview_paragraph_revision |
previewTrackedParagraph / previewParagraphRevision |
| Accept/reject supported anchored revision(s) | preview_revision |
preview_revision |
previewRevision |
| Insert a paragraph after a direct body paragraph | preview_with_paragraphs / ParagraphInsertion |
preview([], paragraph_insertions=[edit]) |
preview({paragraphInsertions: [edit]}) |
| Replace/remove a paragraph, replace section content or patch keep-with-next | BlockEdit / preview_blocks |
preview([], block_edits=[edit]) |
preview({blockEdits: [edit]}) |
| Insert/replace a direct inline or patch modeled direct run formatting | InlineEdit / preview_with_inlines |
preview([], inline_edits=[edit]) |
preview({inlineEdits: [edit]}) |
| Format runs in body cells, hyperlinks, shared section stories or ordinary entries | edit_run_format(owner, &[edit]) |
edit_run_format([edit], owner_part=part) |
editRunFormat({ownerPart, inlineEdits: [edit]}) |
| Insert/remove rows, cells or columns; replace cell contents | TableStructureEdit / preview_with_table_structure |
preview([], table_structure=[edit]) |
preview({tableStructure: [edit]}) |
| Set/clear direct table layout (same batch field) | TableOperation::Layout(Some(TableLayout::Fixed)) / Layout(None) |
TableStructureEdit.layout(target, "fixed") / layout(target, None) |
{target, kind: "layout", value: "fixed"} / value: null |
| Inspect/patch a direct table, row or cell property | properties / TableOperation::Property { site, field, source } |
properties / TableStructureEdit.patch_property(target, field, source, ...) |
properties / {target, kind:"patchProperty", field, source, ...} |
| Replace table/row/cell or remove table | TableOperation::ReplaceNode / RemoveTable |
TableStructureEdit.replace_node(...) / remove_table(target) |
kind: "replaceNode" / "removeTable" |
| Discover and edit nested or non-body tables | part_tables(Some(owner)) / edit_part_tables(owner, &edits) |
part_tables(owner) / edit_part_tables(owner, edits) |
partTables(owner) / editPartTables({ownerPart, tableStructure}) |
| Edit supported style definitions | StyleEdit / preview_with_styles |
preview([], style_edits=[edit]) |
preview({styleEdits: [edit]}) |
| Set/clear title, default alignment or abstract level start | ResourceEdit / preview_with_resources |
preview([], resources=[edit]) |
preview({resources: [edit]}) |
| Edit simple text in a physical header/footer, footnote/endnote or comment part | edit_story_text(owner_part, edits) |
edit_story_text(owner_part, edits) |
editStoryText({ownerPart, runText}) |
| Insert/replace an ordinary note/comment inline or patch run bold | edit_entry_inlines(owner_part, edits) |
edit_entry_inlines(owner_part, edits) |
editEntryInlines({ownerPart, inlineEdits}) |
| Create, attach, detach, retarget, renumber or delete an ordinary direct-body note reference | edit_note_reference(owner, &target, NoteReferenceEdit) |
edit_note_reference(owner, target, kind, **fields) |
editNoteReference({ownerPart, target, kind, ...fields}) |
| Edit entry paragraphs, base comment metadata or delete an unused ordinary note | edit_entry(owner, id, EntryEdit) |
edit_entry(owner, id, kind, **fields) |
editEntry({ownerPart, id, kind, ...fields}) |
| Set a direct body table cell's vertical alignment | preview_with_cells / CellAlignmentEdit |
preview([], cell_alignments=[edit]) |
preview({cellAlignments: [edit]}) |
| Replace a plain paragraph scalar range | preview_with_ranges / TextRangeEdit |
preview([], text_ranges=[edit]) |
preview({textRanges: [edit]}) |
| Insert text at a plain paragraph scalar position | EditBatch::text_insertions / TextInsertion |
preview([], text_insertions=[edit]) |
preview({textInsertions: [edit]}) |
| Replace text in a direct body run | doc.preview_with_text(&[], &[], &[], &[edit])? |
doc.preview([], run_text=[edit]) |
doc.preview({runText: [edit]}) |
| Remove a direct body run | doc.preview_with_run_removals(&[], &[], &[], &[], &[anchor])? |
doc.preview([], run_removals=[anchor]) |
doc.preview({runRemovals: [anchor]}) |
| Inspect removed runs | preview.run_removals() |
preview.run_removals |
preview.runRemovals() |
| Inspect changed runs | preview.run_text_changes() |
preview.run_text_changes |
preview.runTextChanges() |
Entries include the original ID, note type or comment metadata, and direct paragraphs with snapshot-scoped inline anchors. Tables and other block types are opaque in these stories.
Use RunTextEdit { target, text } in Rust, RunTextEdit(target, text) in Python,
or {target, text} in JavaScript. The run must
contain a single text element outside fields and ranges. Formatting, adjacent
runs and opaque siblings survive. Tabs, line breaks, mixed-content runs,
duplicate targets and stale anchors reject the entire batch.
Removal deletes the whole selected run, not just its text. It accepts only
single-text direct body runs with recognized local formatting; unknown attributes,
complex properties, revisions, mixed content and protected ranges are rejected.
Replacement and removal of the same anchor conflict.
- Rust consumes declarations; Python leaves them unchanged. Resolve once to render repeatedly without rerunning producers or rereading images.
- Compose with an unsigned Transitional DOCX or DOTX template; output is DOCX. Inspect and preview edits on an unsigned DOCX using targets from the same snapshot. Image appends support effective default, first and even headers and footers. A shared edit affects every alias of the physical part; a section-local edit forks the selected slot. See the editor inventory for target and preservation limits.
- Template replacement can span runs within a paragraph or hyperlink. It cannot cross structured boundaries or change fields, revisions or controls. Replacement text belongs to the first matched run; bookmark/comment markers and untouched break attributes stay in place.
- Untouched part payloads retain their bytes. Edited XML and the ZIP container may be reserialized. Related parts are found by relationship, not filename; invalid internal relationships fail. Path output replaces the destination only after compilation, using a sibling temporary file.
- Packages declaring a digital-signature origin are rejected, even without edits. Use an unsigned copy; rocx does not strip, verify or renew signatures.
- On edited parts, unsupported or unbound
mc:MustUnderstandnamespaces on WordprocessingML elements are rejected. The guard recognizes Transitional WordprocessingML, Office relationships and XML. It does not selectAlternateContentbranches or scan foreign subtrees and untouched opaque parts. - When opening a Word part, a visible wrapper matched by a local or inherited
mc:ProcessContentrule is rejected. Otherwise an MCE consumer could expose additional properties, inline nodes or range markers that the editor did not address. Unmatched foreign wrappers remain opaque; unused rules and lazy, unrelated parts do not block editing.