Skip to content

Apply multiple styles within a single paragraph or sentence #851

@dgonzo27

Description

@dgonzo27

I am consuming a word doc as a template, then when a user downloads the document, certain fields in that document are populated with some user data. The problem is when I am trying to add character styling to specific runs within a paragraph:

para.add_run(some_value, style='black-char-style')
para.add_run(next_value, style='red-char-style')

I even tried to insert a paragraph before:

para.insert_paragraph_before(some_value, style='black-paragraph')
para.insert_paragraph_before(next_value, style='red-paragraph')
para.clear()

Another take:

para.insert_paragraph_before(some_value, style='black-paragraph')
para.clear # or para.text = ''
para.add_run(next_value, style='red-char-style')

The result is either all black text or all red text, depending on which is set first. This is similar to the open issue in regard to splitting runs. I wrote my own functions to handle parsing out the strings I'm looking to add as a run, and it does so successfully, but the issue comes in styling.

Any suggestions, remediations, or upcoming class-based/api functions that allow for multiple styles to be set within a paragraph or sentence?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions