我有一个 Word (.docx) 文档,其中包含标题/标题及其在标题下方的相应表格,如下所示:
1.1.1.1 Table_Title_001
Name Gautham
College Oxford
University Cambridge
1.1.1.2 Table_Title_002
Name Krishnan
College Harvard
University Stanford
有什么办法可以用Python提取每张表的标题吗? win32com 或 python-docx 的文档对此不是很清楚。
请您参考如下方法:
我现在不在 Windows 上,所以我无法在本地测试它,但 Word 表格有一个 Title property这似乎就是您要找的东西。
使用 win32com,它看起来像这样:
from win32com import client
word = client.Dispatch("Word.Application")
document = word.Documents.Open(path_to_docx)
titles = [table.Title for table in document.Tables]
