docx_plus.fields.update¶
Mark every field in a document for recalculation on the next Word
open. Sets <w:updateFields w:val="true"/> in settings.xml. Word
flips the flag back to false after recalculating — it's a one-shot
mechanism, not persistent state.
mark_fields_dirty is idempotent: a second call updates the existing
element rather than duplicating it.
docx_plus.fields.update ¶
Mark fields dirty so Word recalculates them on next open.
A complex field stores both an instruction (w:instrText) and a cached
result (w:t). Word will display the cached result unless it is told to
recalculate. Setting <w:updateFields w:val="true"/> in settings.xml
flips a one-shot flag — Word resolves every field in the document on open,
then clears the flag back to false so the recalculation does not repeat.
This module imports only from docx_plus.core (SPEC §9.1).
mark_fields_dirty ¶
Set w:updateFields="true" in settings.xml.
Idempotent: calling twice produces a single w:updateFields element.
If an existing element has w:val="false", it is updated to "true".
Should a malformed settings.xml (e.g. from another tool) contain
several w:updateFields copies, they are collapsed to one set to
"true" — leaving a stale duplicate behind would let Word read the
wrong value (CT_Settings permits at most one).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
doc
|
Document
|
The python-docx :class: |
required |
Example
from docx import Document from docx_plus.fields import add_page_number_field, mark_fields_dirty doc = Document() p = doc.add_paragraph("Page ") _ = add_page_number_field(p) mark_fields_dirty(doc)