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')
来源:oschina
链接:https://my.oschina.net/u/4271883/blog/4365677