我需要生成一个word文档,其中已创建了一个表。每行中的列数是动态的,具体取决于行号(默认为2,否则大于2)。所以我想知道如何使用python-docx拆分单元格。
这是我编写的示例代码,给我一个错误
from docx import Document
from docx.shared import Inches
def main():
document = Document()
document.add_heading('Message Format')
msgFormatTable = document.add_table(rows = 0, cols = 2, style = 'Table Grid')
for i in range(1, 5):
row_cells = msgFormatTable.add_row().cells
j = 1
while j < i:
row_cells[j].split(i, j + 1)
j += 1
document.save("tee.docx")
main()
我收到 AttributeError:“ _ Cell”对象在运行时没有属性“ split” 错误