Выделите текст в python и сохраните его в файле Word.

Я пытаюсь взять текст из файла слова и выделить нужный текст, и старение хочу сохранить текст в новый файл слова.

Я могу выделить текст, используя escape-последовательности ANSI, но не могу добавить его обратно в файл слова.

from docx import Document
doc = Document('t.docx')
##string present in t.docx '''gnjdkgdf helloworld dnvjk dsfgdzfh jsdfKSf klasdfdf sdfvgzjcv'''

if 'helloworld' in doc.paragraphs[0].text:    
    high=doc.paragraphs[0].text.replace('helloworld', '\033[43m{}\033[m'.format('helloworld'))


doc.add_paragraph(high)
doc.save('t1.docx')

получение этой ошибки.

ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

person harsha    schedule 11.05.2017    source источник


Ответы (1)