设置页边距

from  docx  import  Document
from  docx.shared  import  Cm
文件=Document(r'E:word练习页眉页脚.docx')
第一节=文件.sections[0]
print("上边距:",第一节.top_margin.cm)
print("下边距:",第一节.bottom_margin.cm)
print("左边距:",第一节.left_margin.cm)
print("右边距:",第一节.right_margin.cm)

#设置页面边距
第一节.top_margin=Cm(5)
第一节.bottom_margin=Cm(5)
第一节.left_margin=Cm(4)
第一节.right_margin=Cm(4)

文件.save(r'E:word练习设置页边距.docx')
原文地址:https://www.cnblogs.com/luckiness/p/13287299.html