当前位置: 首页 > news >正文

移动官网网站建设屏幕分辨率 网站开发

移动官网网站建设,屏幕分辨率 网站开发,域名连接到网站怎么做,中国黑色网站模板python word 读取section.page_height参数错误 最近在做报告自动化,发现调用word模板,或程序新建模板,只要调用section.page_height获得的页数据就不正常, from docx import Document from docx.shared import Cm, Twipsdoc D…

python  word 读取section.page_height参数错误

最近在做报告自动化,发现调用word模板,或程序新建模板,只要调用section.page_height获得的页数据就不正常,

from docx import Document
from docx.shared import Cm, Twipsdoc = Document()
section = doc.sections[0]print("Page Height (Twips):", section.page_height)  # 正常应为 15840
print("Page Height (Cm):", Twips(section.page_height).cm)  # 直接转换为厘米
D:\od172406\venv\Scripts\python.exe D:\od172406\常用文件\调试\sdfdsfaa.py 
Page Height (Twips): 10058400
Page Height (Cm): 17741.9进程已结束,退出代码为 0

(venv) D:\od172406 git:[master]
pip install --upgrade python-docx
Requirement already satisfied: python-docx in d:\od172406\venv\lib\site-packages (1.0.1)
Collecting python-docx
  Using cached python_docx-1.1.2-py3-none-any.whl.metadata (2.0 kB)
Requirement already satisfied: lxml>=3.1.0 in d:\od172406\venv\lib\site-packages (from python-docx) (5.4.0)
Requirement already satisfied: typing-extensions>=4.9.0 in d:\od172406\venv\lib\site-packages (from python-docx) (4.13.2)
Using cached python_docx-1.1.2-py3-none-any.whl (244 kB)
Installing collected packages: python-docx
  Attempting uninstall: python-docx
    Found existing installation: python-docx 1.0.1
    Uninstalling python-docx-1.0.1:
      Successfully uninstalled python-docx-1.0.1
Successfully installed python-docx-1.1.2

换了几个版本的python_docx,都是如此结果,是什么变了呢

最后只有换思路实现课任务,在此记录,有时间好好研究一下。

from docx import Document
from docx.shared import Cm, Twipsdoc = Document()
section = doc.sections[0]
print(section)
from docx.shared import Cm, Pt
# 设置页面高度为29.7厘米(A4纸的高度)
section.page_height = Cm(29.7)
print("Page Height (Twips):", section.page_height)  # 正常应为 15840
print("Page Height (Cm):", Twips(section.page_height).cm)  # 直接转换为厘米

结果:

D:\od172406\venv\Scripts\python.exe D:\od172406\常用文件\调试\sdfdsfaa.py 
<docx.section.Section object at 0x0000021D756B9D30>
Page Height (Twips): 10692130
Page Height (Cm): 18859.729305555556

进程已结束,退出代码为 0

有空研究,查清了原因,版本升级后单位变了

from docx import Document
from docx.shared import Cm, Twipsdoc = Document()
section = doc.sections[0]
print(section)
from docx.shared import Cm, Pt
# 设置页面高度为29.7厘米(A4纸的高度)
print("Page Height (Emus):", section.page_height)  # 正常应为 15840
section.page_height = Cm(29.7)
print("Page Height Emus):", section.page_height)  # 正常应为 15840
print("Page Height (Twips):", section.page_height/635)  # 正常应为 15840
print("Page Height (Cm):", section.page_height/Cm(1.0))  # 直接转换为厘米
print('cm',Cm(1.0))
print('ccc,',section.page_height/Cm(1.0))

<docx.section.Section object at 0x0000017D519C1AF0>
Page Height (Emus): 10058400
Page Height Emus): 10692130
Page Height (Twips): 16838.0
Page Height (Cm): 29.70036111111111
cm 360000
ccc, 29.70036111111111
Page Height (Cm): 29.70036111111111
 

查看文件原码:

class Length(int):"""Base class for length constructor classes Inches, Cm, Mm, Px, and Emu.Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to themm. Provides convenience unit conversion methods in the form of read-onlyproperties. Immutable."""_EMUS_PER_INCH = 914400_EMUS_PER_CM = 360000_EMUS_PER_MM = 36000_EMUS_PER_PT = 12700_EMUS_PER_TWIP = 635
http://www.dtcms.com/a/594581.html

相关文章:

  • “人机交互”中语音识别浅析
  • PPT图标大小怎么调才协调?与文字的比例是多少 ?
  • PPT 素材版权风险解析与合规素材获取指南
  • 什么平台做网站wordpress+爱情模板
  • 做视频网站需要什么职位工作做网站后期续费是怎么算的
  • XSLT `<value-of>` 元素详解
  • 网站收录查询方法淘宝美工做兼职的网站
  • 如何电话推销客户做网站网站制作致谢词
  • 嘉兴网站的优化wordpress ajax加载
  • 东莞网站竞价推广运营网站建设的需要分析
  • #HarmonyOS篇:管理组件拥有的状态状态管理V2
  • Boost库中boost::assign的使用
  • Swift-static和class
  • 个人网站设计规划书塘沽网站制作
  • 寻找富阳网站建设短视频矩阵营销
  • (已完结)仿神秘海域/美末环境交互的程序化动画学习
  • 网站后台怎么上传文章百度网站排名优化软件
  • 【菜狗学编程】opencv、numpy简单基础——20251011
  • 网站开发一个模板费用优惠券网站要怎么做的
  • 做cra需要关注的网站国际物流网站建设
  • Linux 文件
  • MCU 内存栈介绍和内存段
  • 如何配置Dev-C++的环境变量到系统路径?
  • 在网站和网页的区别哪里有培训网
  • 洪梅网站建设网站开发所需费用支出有哪些
  • 个人网站首页模板彩票网站开发演示
  • 企业网站未来发展趋势网站推广怎么推广
  • 芯伯乐3A降压稳压器XBLW LM2576/LM2596:高效、高可靠性开关电源解决方案
  • 30V N 沟道 MOSFET SP30N03BNK 规格解析与应用场景详解
  • JSON格式爬取淘宝/1688/京东商品详情API接口实战指南