实现docx表格中指定行新增插入新的一行(已解决)

利用docx包或者其他功能模块,实现在原docx表格 table[0]中第八行插入,新插入的行则为第九行(即插入点在原第八行与第九行之间)。

Jason990420
最佳答案

python-docx 0.8.10 documentation

table.rows

_Rows, instance containing the sequence of rows in this table.

table.rows[n]._tr.addnext(element)

Adds the element as a following sibling directly after this element.

This is normally used to set a processing instruction or comment after the root node of a document. Note that tail text is automatically discarded when adding at the root level.

table.rows[n]._tr.addprevious(element)

Adds the element as a preceding sibling directly before this element.

This is normally used to set a processing instruction or comment before the root node of a document. Note that tail text is automatically discarded when adding at the root level.

3年前 评论
hkflyman (楼主) 3年前
讨论数量: 2
Jason990420

python-docx 0.8.10 documentation

table.rows

_Rows, instance containing the sequence of rows in this table.

table.rows[n]._tr.addnext(element)

Adds the element as a following sibling directly after this element.

This is normally used to set a processing instruction or comment after the root node of a document. Note that tail text is automatically discarded when adding at the root level.

table.rows[n]._tr.addprevious(element)

Adds the element as a preceding sibling directly before this element.

This is normally used to set a processing instruction or comment before the root node of a document. Note that tail text is automatically discarded when adding at the root level.

3年前 评论
hkflyman (楼主) 3年前
Jason990420

为了产生不同的变量, 比自建一个简单吧.

3年前 评论
hkflyman (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!