-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
I want to extract tuples like("户名", "张三"),("户号", "1102"), but I found I cannot locate values correctly using the following code:
from docx import Document
file = '/paht/to/my_doc.docx'
doc = Document(file)
tables = doc.tables
table = tables[0] # now, I get the table object successfully
# Intuitively, "户 名" is in the first cell of second row. When I try to find it:
row_num = 1
cell_num = 0
row = table.rows[row_num]
cell = row.cells[cell_num]
print(cell.text) # will print "张三"
# Actually,"户 名" is in the last cell of first row:
row_num = 0
row = table.rows[row_num]
cell = row.cells[-1]
print(cell.text) # will print "户 名"Could anybody please tell me what's wrong with it:)
hf-kklein
Metadata
Metadata
Assignees
Labels
No labels
