安裝python-docx
pip install python-docx
如果python2安裝后不能使用(找不到包),建議直接使用python3,安裝代碼如下
pip3 install python-docx
from docx import Documentfrom docx.shared import Pt # 簡單的打開word,輸入數(shù)據(jù),關(guān)閉worddocument = Document()# 向word里增加段落document.add_paragraph('hello')document.save('test.docx') # 在一個段落中增加文字document = Document()paragraph = document.add_paragraph('Normal text, ')# 增加文字paragraph.add_run('add text') # 設置word字體大小style = document.styles['Normal']font = style.fontfont.size = Pt(10)document.save('test.docx')以上這篇Python 實現(xiàn)向word(docx)中輸出就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答