Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用python编写docx表的序列号_Python_List_Docx_Python Docx - Fatal编程技术网

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

如何用python编写docx表的序列号,python,list,docx,python-docx,Python,List,Docx,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

我有很多输入,我想用序列号将它们写在.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

你的问题是什么?我不能用序列号保存docx.table文件。你的问题代码有效吗?它会创建一个表吗?应该很清楚如何修改它以添加另一个带有行号的列。是的,我的代码是工作的。是的,代码是工作的。。。。非常感谢你。