Python之word表格操作


#coding=utf-8
from docx import Document
from docx.shared import Pt
from docx.shared import Inches
from docx.oxml.ns import qn
import docx
#打開文檔
from urllib3.connectionpool import xrange


path_model = '報告.docx'
# document = docx.Document(path_model)
document = Document()
#增加表格
table = document.add_table(rows=1, cols=3,style='Table Grid')
hdr_cells = table.rows[0].cells
hdr_cells[0].text = '姓名'
hdr_cells[1].text = '年齡'
hdr_cells[2].text = '性別'
#再增加3行表格元素,后期是獲取的長度,3為變量
for i in xrange(3):
row_cells = table.add_row().cells
row_cells[0].text = '鳥叔'
row_cells[1].text = str(i + 10)
row_cells[2].text = '男'



document.save(path_model)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM