python-docx about unusual operating
from docx import Document
document = Document
table = document.add_table(rows=2, cols=3)
# set the whole table in the center position table.alignment = WD_TABLE_ALIGNMENT.CENTER
# set every single cell center
for row in table.rows: row.height = Inches(1) for cell in row.cells:
# set colums center cell.vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER paragraphs = cell.paragraphs for paragraph in paragraphs:
# set each cell center paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER for run in paragraph.runs: font = run.font font.size = Pt(22)
row_cell = table.add_row().cells
# choice one row row_pic = row_cell[0]
# clear blank area row_pic._tc.clear_content()
# use paragraph function pic_run = row_pic.add_paragraph().add_run()
# insert a picture path as a str into a cell from a table pic_run.add_picture('./picture/{}'.format("picture_name.jpg"), width=Inches(5))
one way to change the font size from paragraph:
p = document.add_paragraph() # there is not just set current paragraph font size ,also set the # whole word enter blank,which means every enter as size as # there font size. if the other paragraph set font size as this # way, they will change together and you should care about that. p.style.font.size = Pt(22)
the other way :
run = p.add_run(u'hello world') # there is another way set font size ,different from upton ,only # set current paragraph,the key is function ==>app_run() after it. run.font.size = Pt(22)