使用 python 填写 word 表格
生活随笔
收集整理的這篇文章主要介紹了
使用 python 填写 word 表格
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用 python 填寫 word 表格
- 用 python 填寫 word 表格
- 安裝 Python-docx 包
- 整個代碼
用 python 填寫 word 表格
下面的代碼段不包含格式處理,僅能改變表格單元格內容。
安裝 Python-docx 包
直接在命令行輸入:pip install python-docx 即可
程序中 import docx
整個代碼
#打開或創建word文檔 doc_name = "E:\\study\\a.docx" doc = docx.Document(doc_name)#.....中間代碼略#獲取表格,將計算出精度指標填入word文檔 #word中第1個表格為doc.tables[0] table = doc.tables[j + 3 * i + 1] # 對表格的第Trow行,第1、2、3、5列單元格填寫數據 #bias等浮點型數據四舍五入保留小數點后兩位 table.cell(Trow, 1).text = "%.2f" % bias table.cell(Trow, 2).text = "%.2f" % biasabs table.cell(Trow, 3).text = "%.2f" % rmse table.cell(Trow, 5).text = "%.2f" % dc#保存對word表格做的改變 new_doc_name = "E:\\study\\a1.docx" doc.save(new_doc_name)總結
以上是生活随笔為你收集整理的使用 python 填写 word 表格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 星空主题设计理念_星空?这样才有的空间感
- 下一篇: 第二章-Coin Dash