Created
          January 3, 2018 07:05 
        
      - 
      
 - 
        
Save MattHealy/4b031c4bb072d9679d0bd7cfd678ff0f to your computer and use it in GitHub Desktop.  
    python-docx example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def merge(r): | |
| if '{{LESSOR}}' in r.text: | |
| r.text = r.text.replace('{{LESSOR}}', 'my name') | |
| if '{{LESSORADDRESS}}' in r.text: | |
| r.text = r.text.replace('{{LESSORADDRESS}}', 'my address') | |
| from docx import Document | |
| document = Document('input.docx') | |
| for t in document.tables: | |
| for r in t.rows: | |
| for c in r.cells: | |
| for p in c.paragraphs: | |
| for r in p.runs: | |
| merge(r) | |
| document.save('output.docx') | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment