Skip to content

Instantly share code, notes, and snippets.

@garymanley
Last active December 27, 2017 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garymanley/98a6880cb1eabe930a3b9a09fba8232b to your computer and use it in GitHub Desktop.
Save garymanley/98a6880cb1eabe930a3b9a09fba8232b to your computer and use it in GitHub Desktop.
PythondocxTest
#### docx and pandas imports
from docx import Document
import pandas as pd
from docx.shared import RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.shared import Cm , Pt
# create new document
document = Document()
#set up font
font = document.styles['Normal'].font
font.name = 'Arial'
font.size = Pt(10)
# set up margins
sections = document.sections
for section in sections:
section.top_margin = Cm(1.25)
section.bottom_margin = Cm(1.25)
section.left_margin = Cm(1.75)
section.right_margin = Cm(1.75)
# Add some text
p = document.add_paragraph()
p.add_run('Hello World')
# Add a heading, level 2
document.add_heading('Profile', level=2)
# Save document
document.save(r'Document.docx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment