from docx
import Document
from docx
.shared
import Pt
doc
= Document
()
path
= "C:\\Users\\Administrator\\Desktop\\word文档\\"
doc
.add_picture
(path
+ 'cat.jpg', width
=Pt
(300))
doc_table
= doc
.add_table
(rows
=4, cols
=3, style
='Medium List 1 Accent 1')
doc_table
.rows
[0].cells
[0].text
= '姓名'
doc_table
.rows
[0].cells
[1].text
= '性别'
doc_table
.rows
[0].cells
[2].text
= '兴趣'
date
= (
("张三", "男","篮球"),
("李四", "男","乒乓球"),
("王舞", "女","羽毛球"),
)
for a
,b
,c
in date
:
new_row
= doc_table
.add_row
()
new_row
.cells
[0].text
= a
new_row
.cells
[1].text
= b
new_row
.cells
[2].text
= c
doc
.save
(path
+ "new.doc")
效果图如下: 喜欢的点个赞❤吧!
转载请注明原文地址: https://lol.8miu.com/read-26070.html