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的宽高互换。

相关链接

页面尺寸和方向

相关推荐
Highcharts.js3 小时前
Highcharts 云端渲染的真相:交互式图表与服务器端生成的边界
前端·信息可视化·服务器渲染·highcharts·图表渲染
zhuyan1084 小时前
Linux 系统磁盘爆满导致无法启动修复指南
前端·chrome
编程牛马姐5 小时前
独立站SEO流量增长:提高Google排名的优化方法
前端·javascript·网络
NotFound4865 小时前
实战指南如何实现Java Web 拦截机制:Filter 与 Interceptor 深度分享
java·开发语言·前端
Dontla5 小时前
高基数(High Cardinality)问题介绍(Prometheus、高基数字段、低基数字段)
前端·数据库·prometheus
whuhewei8 小时前
为什么客户端不存在跨域问题
前端·安全
妮妮喔妮8 小时前
supabase的webhook报错
开发语言·前端·javascript
qq_12084093718 小时前
Three.js 大场景分块加载实战:从全量渲染到可视集调度
开发语言·javascript·数码相机
yivifu8 小时前
手搓HTML双行夹批效果
前端·html·html双行夹注
奔跑的卡卡9 小时前
Web开发与AI融合-第一篇:Web开发与AI融合的时代序幕
前端·人工智能