Skip to content

Instantly share code, notes, and snippets.

@K4zuki
Last active October 23, 2017 05:53
Show Gist options
  • Save K4zuki/0f80f657b7c982038c8e0933eb0e30b1 to your computer and use it in GitHub Desktop.
Save K4zuki/0f80f657b7c982038c8e0933eb0e30b1 to your computer and use it in GitHub Desktop.
python-docx to change table style
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
opens a docx file, replace ALL table style(*) and save on same file
mainly for pandoc exported docx file
(*) the applying style must be pre-defined in given file
Applies MIT License - 2017 K4ZUKI(K4zuki@github.com)
"""
import docx # python-docx 0.8.6+
docu = docx.Document("file.docx")
for tbl in docu.tables:
tbl.style = "Table Grid"
docu.save("file.docx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment