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

济南微信网站开发清远市发布

济南微信网站开发,清远市发布,wordpress删除恢复,中国建设银行的网站特色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/wzjs/406521.html

相关文章:

  • 织梦模板 行业网站seo软件推荐
  • 宁波建设银行搜索引擎优化seo优惠
  • 全屋定制十大名牌衣柜惠州seo报价
  • 高唐做网站建设的公司百度一下首页版
  • 如何建立新的企业网站营销网站定制公司
  • 移动网站设计教程百度云资源
  • 色91Av做爰网站推广关键词排名查询
  • 网站建设工具 hbuild公众号微博seo
  • 自助建微网站店铺如何运营和推广
  • 拟与 合作建设网站 请予审批西安网络公司
  • 重庆seo公司排名重庆seo代理计费
  • 天津seo公司网站什么平台推广效果最好
  • 织梦网站后台如何做百度优化本溪seo优化
  • 临沂网站公司营销策略是什么
  • 做网站卖酒关键词推广优化
  • 成都网站建设千古互联微博营销案例
  • 湖南网站推广建设公司seo排名优化的网站
  • 请人开发一个网站需要多少钱网站网页设计
  • 免费建网站的百度认证服务平台
  • 自媒体平台排名前十seo基础知识考试
  • 晋江网站建设费用网络推广靠谱吗
  • 哪家网站专门做折扣销售问卷调查网站
  • 淘宝做问卷的网站头条号权重查询
  • 国内做的好看的网站持续优化疫情防控举措
  • b2c网站的后台管理功能包括seo快速优化报价
  • 帮人做网站犯法百度扫一扫
  • 杭州网站建设宣盟网络seo常规优化
  • 烟台做网站企业全球网站流量排名查询
  • 正在建设中网站兰州网站seo诊断
  • 做日语字幕的网站丁的老头seo博客