Word & layout

In Word, bold is None—so does that count as bolding or not?

’s direct format of None indicates that no value has been set, not False. Here, only the direct format and the explicit character style chain are checked; when

阅读文本 / Reading text
This paper uses synthetic samples to demonstrate the processing method. The code has been verified using examples in an isolated environment; this does not guarantee effectiveness for all real files or products. Before processing important files, please retain the original copies and verify them against the boundaries and acceptance criteria outlined in this document. Which problem does this paper address first ’s direct format of None indicates that no value has been set, not False. Here, only the direct format and the explicit character style chain are checked; when no value is found, None is returned, leaving further parsing to paragraph styles, document defaults, and OOXML toggle rules—thus it cannot be considered a complete and valid style calculator. self-contained synthetic example dependencies are listed in the import section. The code constructs inputs in memory; runtime logs are provided separately and do not constitute a guarantee for all real-world files. from docx import Document from docx.enum.style import WD_STYLE_TYPE def partial_bold(run): if run.bold is not None: return run.bold style, seen = run.style, set() while style is not None and style.style_id not in seen: seen.add(style.style_id) if style.font.bold is not None: return style.font.bold style = style.base_style return None doc = Document() style = doc.styles.add_style("DemoBold", WD_STYLE_TYPE.CHARACTER) style.font.bold = True run = doc.add_paragraph().add_run("Example") run.style = style assert partial_bold(run) is True run.bold = False assert partial_bold(run) is False plain = doc.add_paragraph().add_run("Plain") assert partial_bold(plain) is None understands the three-state logic of style inheritance If the user selects a portion of text in the Word interface and clicks the bold button, the XML will contain <w:b/> , at this point run.bold is True . If the user deliberately removes a formatting effect that should have been applied in bold, the XML will contain <w:b w:val="0"/> , at this point run.bold is False . However, in the vast majority of cases, the text simply lies quietly within the paragraph, without any direct bolding tags; whether it is bolded depends entirely on the style definition to which it belongs. This is None The meaning is: it is not “no,” but rather “please look up.” This design is intended to reduce file size and maintain format consistency. As stated in the official documentation, Built-in Styles are not even written to the file until they are actually used. styles.xml , they exist as “Latent Styles” within the Word application. This means your code must be capable of traversing the style chain, rather than relying solely on the properties of the Run object itself. To safely determine whether text is truly bold, we need to write a recursive function that traverses the style inheritance chain. Please note: The following code is a teaching demonstration example that has been verified using synthetic samples, intended to illustrate three-state decision logic. In a production environment, you must handle circular reference protection, namespace resolution, and additional property types. Acceptance Criteria and Manual Review Boundary Automated parsing can never perfectly emulate Word’s rendering engine. When processing batches of documents, it is essential to establish a clear acceptance matrix that distinguishes between cases where the code can be trusted and those that must be handled manually. Observation of the phenomenon code return value actual rendering processing decision Note Run.bold=None, Style.bold=True True bold ✅ Automatically passed via standard style inheritance scenario Run.bold=False, Style.bold=True False conventional ✅ Automatically passes is explicitly overridden, and the code logic is correct Run.bold=None, Style.bold=None False bold ⚠️ Requires manual review may have omitted docDefaults or the theme font settings style name is the Chinese alias AttributeError - ❌ Block and report an error python-docx has unstable support for localized style names Text in complex list items True/False is uncertain ⚠️ Requires manual review The interaction between list styles and paragraph styles is extremely complex Scope of Non-Applicability Statement: This parsing logic applies only to standard .docx format. For .doc Files converted from other formats, protected documents, or documents whose formatting is dynamically modified by macros may produce code-parsing results that differ significantly from their visual presentation. Furthermore, the code demonstrates attribute-extraction logic rather than end-to-end layout reconstruction; if the goal is to precisely replicate the page layout, relying solely on attribute values is insufficient. References and Next Steps Understanding Styles - python-docx Documentation ECMA-376 Standard: Office Open XML File Formats uses this checklist for document translation Word translations often blur the line between content issues and formatting problems. Leave checks for styles, headers, tables, and other elements to the delivery checklist, so reviewers know where to look. OmniDoc (product entry point) provides an entry point for translating multi-format documents, and the official website highlights its OCR, terminology database, and bilingual alignment features. For teams that wish to start processing directly from files, this is a path worth evaluating with real-world samples. Please use de-identified files that you are authorized to upload, and verify the results against the checklist provided in this document; we do not claim that OmniDoc utilizes the open-source libraries or internal algorithms referenced herein, nor do we substitute examples for formal product performance testing. - 1 -
Updated 2026-10-08