我知道这是一个重复的问题,但这些答案不适用于我。我有一个word文件,其中包含一张表,现在我希望该表格作为我的python程序的输出。我使用Python 3.6,我也安装了python -docx。这里是我的数据提取代码python -docx从word docx中提取表格
from docx.api import Document
document = Document('test_word.docx')
table = document.tables[0]
data = []
keys = None
for i, row in enumerate(table.rows):
text = (cell.text for cell in row.cells)
if i == 0:
keys = tuple(text)
continue
row_data = dict(zip(keys, text))
data.append(row_data)
print (data)
我想要的结果什么看起来在word docx文件。在此先感谢
问题是?错误? –
我试过你的代码,它适用于我。 –