當前位置:首頁 » 編程語言 » python操作word

python操作word

發布時間: 2022-12-16 00:44:32

① 如何用python讀取word

使用Python的內部方法open()讀取文本文件

try:
f=open('/file','r')
print(f.read())
finally:
iff:
f.close()

如果讀取word文檔推薦使用第三方插件,python-docx 可以在官網上下載

使用方式

#-*-coding:cp936-*-
importdocx
document=docx.Document(文件路徑)
docText=' '.join([
paragraph.text.encode('utf-8')forparagraphindocument.paragraphs
])
printdocText

② python怎麼在word表中插圖片

# -*- coding: UTF8 -*-from docx import Documentfrom docx.shared import Pt doc = Document() # 文件存儲路徑path = "C:\\Users\\Administrator\\Desktop\\word文檔\\" # 讀取文檔# doc = Document(path + "hello.docx") # 添加圖片,後面的參數設置圖片尺寸,可以選填doc.add_picture(path + 'cat.jpg', width=Pt(300))

熱點內容
同等配置的聯想和戴爾哪個更好 發布:2025-07-02 09:02:33 瀏覽:123
華為如何查詢以前設置過的密碼 發布:2025-07-02 09:02:28 瀏覽:181
c語言地圖 發布:2025-07-02 09:00:14 瀏覽:488
計算機的主存儲器是指軟盤的容量 發布:2025-07-02 08:53:49 瀏覽:237
為什麼都說歐曼價格高配置低 發布:2025-07-02 08:53:00 瀏覽:547
300人用什麼電腦伺服器好 發布:2025-07-02 08:47:42 瀏覽:902
52好壓縮 發布:2025-07-02 08:24:16 瀏覽:246
javahttp發送http請求 發布:2025-07-02 08:17:05 瀏覽:226
美國編譯的青少經典書第三輯 發布:2025-07-02 08:16:59 瀏覽:949
阿里雲伺服器強制重啟 發布:2025-07-02 08:14:55 瀏覽:663