python将Word页面纸张方向设置为横向

通过python-docx的章节属性,就可以更改纸张方向、纸张尺寸。

python 复制代码
import docx
from docx.enum.section import WD_ORIENT
from docx.shared import Cm

document = docx.Document()
section = document.sections[0]

# 设置纸张大小为A4大小
section.page_width = Cm(21)
section.page_height = Cm(29.7)

# 设置纸张方向横向,横向是LANDSCAPE,竖向是PORTRAIT
section.orientation = WD_ORIENT.LANDSCAPE

# 设置章节宽高,也就是宽高互换
section.page_width, section.page_height = section.page_height, section.page_width
document.save('landscape.docx')

更改纸张方向,分两步,第一步是设置section的orientation属性为LANDSCAPE,第二步是设置section的宽高互换。

相关链接

页面尺寸和方向

相关推荐
Aotman_6 小时前
Element UI 表格搜索高亮
前端·javascript·vue.js·ui·elementui
小矮强6 小时前
Word总页码减去首页
word
Dillon Dong6 小时前
【系列主题】拯救 OOM 与构建中断:Next.js 在 Docker 中的静态生成(SSG)避坑指南
开发语言·javascript·docker
han_hanker7 小时前
下拉模糊搜索多选, 编辑,详情问题
开发语言·javascript·ecmascript
yqcoder7 小时前
[特殊字符] Vue 3 中 Keep-Alive 对生命周期的影响:深度解析
前端·javascript·vue.js
jiayong237 小时前
第 33 课:任务看板视图(按状态分列)与本地持久化
开发语言·前端·javascript·学习
GISer_Jing7 小时前
Dify可视化编排:技术架构与实战指南
前端·人工智能·ai编程
宇宙realman_9997 小时前
DSP28335-FlashAPI使用
linux·前端·python
踩着两条虫8 小时前
VTJ 平台六大设计模式落地实战指南
开发语言·前端·人工智能·低代码·设计模式·重构·架构
Yeats_Liao8 小时前
后台 Sidebar 伸缩交互(PC + 移动端)实现
前端·javascript·css·html5