Lost formatting and image after search and replace using python-docx -
experts,
i have template docx report, has image , standard formatting inside it. did using docx, search tags, , replace using value config file.
search & replace working expected, output file lost image, , formatting. know went wrong? did modifying example-makedocument.py, , replace use docx file.
i've searched discussion on python.docx librelist, , page on github, there lot of questions this, remained unanswered.
thank you.
--- script simple 1 ---
from docx import * configparser import safeconfigparser filename = "template.docx" document = opendocx(filename) relationships = relationshiplist() body = document.xpath('/w:document/w:body',namespaces=nsprefixes)[0] ####### config file parser = safeconfigparser() parser.read('../testing1-config.txt') ######## search , replace print 'searching in paragraph ...', if search(body, ''): print 'found it!' else: print 'nope.' print 'replacing ...', body = advreplace(body, '', parser.get('asd', 'asd')) print 'done.' ####### #create our properties, contenttypes, , other support files title = 'python docx demo' subject = 'a practical example of making docx python' creator = 'mike maccana' keywords = ['python', 'office open xml', 'word'] coreprops = coreproperties(title=title, subject=subject, creator=creator,keywords=keywords) appprops = appproperties() contenttypes = contenttypes() websettings = websettings() wordrelationships = wordrelationships(relationships) savedocx(document, coreprops, appprops, contenttypes, websettings, wordrelationships, 'welcome python docx module.docx')
i have answered similar question python-docx. python docx not meant store docx images , export them away.
python docx not templating engine docx.
Comments
Post a Comment