style_name property

Font.style_name property

Gets or sets the name of the character style applied to this formatting.

@property
def style_name(self) -> str:
    ...

@style_name.setter
def style_name(self, value: str):
    ...

Examples

Shows how to change the style of existing text.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Below are two ways of referencing styles.
# 1 -  Using the style name:
builder.font.style_name = 'Emphasis'
builder.writeln('Text originally in "Emphasis" style')
# 2 -  Using a built-in style identifier:
builder.font.style_identifier = aw.StyleIdentifier.INTENSE_EMPHASIS
builder.writeln('Text originally in "Intense Emphasis" style')
# Convert all uses of one style to another,
# using the above methods to reference old and new styles.
for run in doc.get_child_nodes(aw.NodeType.RUN, True):
    run = run.as_run()
    if run.font.style_name == 'Emphasis':
        run.font.style_name = 'Strong'
    if run.font.style_identifier == aw.StyleIdentifier.INTENSE_EMPHASIS:
        run.font.style_identifier = aw.StyleIdentifier.STRONG
doc.save(file_name=ARTIFACTS_DIR + 'Font.ChangeStyle.docx')

See Also