Skip to content

'CT_R' object has no attribute '_new_r' #1522

@QuangMinh94

Description

@QuangMinh94

Hi, I want to create a new run object, so I follow the guide here: https://stackoverflow.com/questions/52740630/python-docx-is-it-possible-to-add-a-new-run-to-paragraph-in-a-specific-place-n

from docx.text.run import Run
from docx.oxml.text.run import CT_R
# ...
for run in p.runs:
    if 'text' in run.text:
        new_run_element = p._element._new_r()
        run._element.addnext(new_run_element)
        new_run = Run(new_run_element, run._parent)
        # ---do things with new_run, e.g.---
        new_run.text = 'Foobar'
        new_run.bold = True

But when I ran the code, I got this error as follow: 'CT_R' object has no attribute '_new_r'

I am using python-docx version 1.2.0

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