From 9748636170c9bcd93de35d72bf93c1b50a261c2a Mon Sep 17 00:00:00 2001 From: Miro <200482516+Mirochill@users.noreply.github.com> Date: Mon, 25 May 2026 21:48:47 +0200 Subject: [PATCH] docs: correct built-in style lookup example --- docs/api/enum/WdBuiltinStyle.rst | 7 +++++-- src/docx/enum/style.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/api/enum/WdBuiltinStyle.rst b/docs/api/enum/WdBuiltinStyle.rst index b7aa682d4..49f10d48c 100644 --- a/docs/api/enum/WdBuiltinStyle.rst +++ b/docs/api/enum/WdBuiltinStyle.rst @@ -10,11 +10,14 @@ Specifies a built-in Microsoft Word style. Example:: from docx import Document - from docx.enum.style import WD_STYLE document = Document() styles = document.styles - style = styles[WD_STYLE.BODY_TEXT] + style = styles["Body Text"] + +A built-in style must be defined in the document before it can be looked up. +Style lookup uses the style's English UI name, e.g. ``"Body Text"``; a +``WD_STYLE`` member like ``WD_STYLE.BODY_TEXT`` is not a style lookup key. ---- diff --git a/src/docx/enum/style.py b/src/docx/enum/style.py index d2474611d..44885d930 100644 --- a/src/docx/enum/style.py +++ b/src/docx/enum/style.py @@ -11,12 +11,15 @@ class WD_BUILTIN_STYLE(BaseEnum): Example:: from docx import Document - from docx.enum.style import WD_STYLE document = Document() styles = document.styles - style = styles[WD_STYLE.BODY_TEXT] + style = styles["Body Text"] + A built-in style must be defined in the document before it can be looked + up. Style lookup uses the style's English UI name, e.g. ``"Body Text"``; + a ``WD_STYLE`` member like ``WD_STYLE.BODY_TEXT`` is not a style lookup + key. MS API name: `WdBuiltinStyle`