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

相关链接

页面尺寸和方向

相关推荐
Rsun045516 小时前
React相关面试题
前端·react.js·前端框架
Lao乾妈官方认证唯一女友:D7 小时前
通过plasmo的wallet扩展添加新钱包
javascript·web3·区块链
ALKAOUA7 小时前
力扣面试150题刷题分享
javascript·笔记
鹏多多.7 小时前
Flutter使用screenshot进行截屏和截长图以及分享保存的全流程指南
android·前端·flutter·ios·前端框架
LawrenceLan7 小时前
37.Flutter 零基础入门(三十七):SnackBar 与提示信息 —— 页面反馈与用户交互必学
开发语言·前端·flutter·dart
迪巴拉15257 小时前
基于Vue与Spring Boot+Open Cv的智慧校园考勤系统
前端·vue.js·spring boot
swipe7 小时前
JavaScript 对象与属性描述符:从原理到实战
前端·javascript·面试
&活在当下&7 小时前
Vue3 h函数用法详解
前端·javascript·vue.js