如何用python编写docx表的序列号

6ojccjat  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(443)

我有许多输入,我想把它们写在.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
lpwwtiir

lpwwtiir1#

如果代码有效,那么这应该是你想要的。

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

相关问题