3
私は単語ファイルからテキストを取り込み、必要なテキストをハイライト表示しようとしています。エージングは新しい単語ファイルにテキストを保存します。pythonのテキストを強調表示して単語ファイルに保存します
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')
このエラーが発生します。代わりに、ANSIのエスケープシーケンスを使用しての、あなたは内蔵のFont highlight colorpython-docx
年代使うことができ
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
を感謝、それは – harsha
グレートを働きました!あなたが問題を解決した場合は、回答を受け入れることができます;)http://stackoverflow.com/help/someone-answers – Josselin