Skip to content

Instantly share code, notes, and snippets.

@ninthhostage

ninthhostage/parsingtables.py Secret

Created Mar 27, 2019
Embed
What would you like to do?
Parsing Docx Tables
from docx import *
filename = 'demo_file.docx'
try:
document = Document(filename)
except:
f = open(filename, 'rb')
document = Document(f)
f.close()
data1 = [0,0,0]
data2 = [0,0,1]
data3 = [0,1,1]
data4 = [0,1,0]
data_wrapper = [data1, data2, data3, data4]
for data in data_wrapper:
table = document.tables[data[0]]
row = table.rows[data[1]]
cell = row.cells[data[2]]
text = cell.text
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment