-
-
Save garymanley/98a6880cb1eabe930a3b9a09fba8232b to your computer and use it in GitHub Desktop.
PythondocxTest
This file contains 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
#### 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