python - 如何在python中写入docx表的序列号
问题描述
我有很多输入,我想将它们写在带有序列号的 .docx 表中
def write():
table = doc.add_table(rows=1, cols=3)
table.style = "Table Grid"
row = table.rows[0].cells
row[0].text = "name and surname"
row[1].text = "relative"
row[2].text = "year of birth"
for name_surname, relative, year_of_birth in data:
row = table.add_row().cells
row[0].text = name_surname
row[1].text = relative
row[2].text = year_of_birth
解决方案
如果该代码有效,那么这应该可以满足您的要求。
def write():
table = doc.add_table(rows=1, cols=4)
table.style = "Table Grid"
row = table.rows[0].cells
row[0].text = "id"
row[1].text = "name and surname"
row[2].text = "relative"
row[3].text = "year of birth"
for idno, (name_surname, relative, year_of_birth) in enumerate(data):
row = table.add_row().cells
row[0].text = str(idno+1)
row[1].text = name_surname
row[2].text = relative
row[3].text = year_of_birth
推荐阅读
- javascript - JSON填充表的搜索功能
- c# - 在 foreach 中添加时间/延迟以读取字符串/Visual Studio 2019 C# Win Forms
- c++ - C++:在一个程序中创建一个指针并在另一个程序中访问该位置
- jquery - javascript:如何从 JSON 对象中检索文件并将其存储到 SharePoint 文档库
- mysql - mysql如何在报告中每月新插入,更新,删除记录的ID
- java - Hibernate/JPA 的新功能:对表主键进行 java.lang.NullPointerException 过滤
- c# - 将新的 VISA 网络设备添加到资源
- prestashop - 模块 Prestashop 1.7:自定义图片上传总是被替换
- jenkins - gitversion 在 windows 上的报告与在 mac 上不同。为什么?
- excel - 在 VBA 代码中计算数组的 IRR