from copy import deepcopy
from docx import Document
filename = r’C:\Users\Administrator\Desktop\python测试\编码区\表4.docx’
document = Document(filename)
table = document.tables[0] # For 1st table
new_table = deepcopy(table)
for a in document.paragraphs:
print(a.text)
paragraph = document.paragraphs[2] #第三段
paragraph.insert_paragraph_before(text=None, style=None)
print(“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”)
paragraph._p.addnext(new_table._element)
for a in document.paragraphs:
print(a.text)
document.save(r’C:\Users\Administrator\Desktop\python测试\编码区\text.docx’)
但是表格结果是,粘贴的表格在第三段之后,非第二段与第三之间(而是为新的空段落)