Skip to content

Commit 5a2da7f

Browse files
Victor VolleSteve Canny
authored andcommitted
docs: add user documentation for Run.style
1 parent 10e77f0 commit 5a2da7f

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

docs/user/quickstart.rst

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ the one above::
221221
p = document.add_paragraph('Lorem ipsum dolor sit amet.')
222222
p.style = 'ListBullet'
223223

224-
Again, the style name is formed by removing the spaces in the name as it
225-
appears in the Word UI. So the style 'List Number 3' would be specified as
226-
``'ListNumber3'``.
224+
The style is specified using its style ID, 'ListBullet' in this example.
225+
Generally, the style ID is formed by removing the spaces in the style name as
226+
it appears in the Word user interface (UI). So the style 'List Number 3'
227+
would be specified as ``'ListNumber3'``. However, note that if you are using
228+
a localized version of Word, the style ID may be derived from the English
229+
style name and may not correspond so neatly to its style name in the Word UI.
227230

228231

229232
Applying bold and italic
@@ -285,3 +288,32 @@ make your code simpler if you're building the paragraph up from runs anyway::
285288
p.add_run('Lorem ipsum ')
286289
p.add_run('dolor').bold = True
287290
p.add_run(' sit amet.')
291+
292+
293+
Applying a character style
294+
--------------------------
295+
296+
In addition to paragraph styles, which specify a group of paragraph-level
297+
settings, Word has *character styles* which specify a group of run-level
298+
settings. In general you can think of a character style as specifying a font,
299+
including its typeface, size, color, bold, italic, etc.
300+
301+
Like paragraph styles, a character style must already be defined in the document you open with the ``Document()`` call (*see* :doc:`styles`).
302+
303+
A character style can be specified when adding a new run::
304+
305+
p = document.add_paragraph('Normal text, ')
306+
p.add_run('text with emphasis.', 'Emphasis')
307+
308+
You can also apply a style to a run after it is created. This code produces
309+
the same result as the lines above::
310+
311+
p = document.add_paragraph('Normal text, ')
312+
r = p.add_run('text with emphasis.')
313+
r.style = 'Emphasis'
314+
315+
As with a paragraph style, the style ID is formed by removing the spaces in
316+
the name as it appears in the Word UI. So the style 'Subtle Emphasis' would
317+
be specified as ``'SubtleEmphasis'``. Note that if you are using
318+
a localized version of Word, the style ID may be derived from the English
319+
style name and may not correspond to its style name in the Word UI.

docs/user/shapes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Conceptually, Word documents have two *layers*, a *text layer* and a *drawing
66
layer*. In the text layer, text objects are flowed from left to right and from
77
top to bottom, starting a new page when the prior one is filled. In the drawing
88
layer, drawing objects, called *shapes*, are placed at arbitrary positions.
9-
and are sometimes referred to as *floating* shapes.
9+
These are sometimes referred to as *floating* shapes.
1010

1111
A picture is a shape that can appear in either the text or drawing layer. When
1212
it appears in the text layer it is called an *inline shape*, or more

docx/text.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ def strike(self):
306306
@property
307307
def style(self):
308308
"""
309-
Read/write. The string name of the character style applied to this
310-
run, or |None| if it has no directly-applied character style. Setting
311-
this property to |None| causes any directly-applied character style
312-
to be removed such that the run inherits character formatting from
313-
its containing paragraph.
309+
Read/write. The string style ID of the character style applied to
310+
this run, or |None| if it has no directly-applied character style.
311+
Setting this property to |None| causes any directly-applied character
312+
style to be removed such that the run inherits character formatting
313+
from its containing paragraph.
314314
"""
315315
return self._r.style
316316

0 commit comments

Comments
 (0)