Modify docx page margins with python-docx

亡梦爱人 提交于 2020-06-14 02:46:27

问题


I need to quickly change the margins of many docx documents. I checked python-docx and I do not find a way to access/modify the page layout (in particular the margins) properties. Is there a way?


回答1:


Thanks to @tdelaney for pointing out the page where it clearly indicated the solution. I am just posting here the code I used in case anyone else is confused as I initially was:

#Open the document
document = Document(args.inputFile)

#changing the page margins
sections = document.sections
for section in sections:
    section.top_margin = Cm(margin)
    section.bottom_margin = Cm(margin)
    section.left_margin = Cm(margin)
    section.right_margin = Cm(margin)

document.save(args.outputFile)


来源:https://stackoverflow.com/questions/32914595/modify-docx-page-margins-with-python-docx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!