Skip to content

Printing Nested Tables #769

@richylyq

Description

@richylyq

HI there, I would like to check if it is possible to print nested tables out using this library? I tried to work on it but however, it just prints the nested table as empty.

from docx import Document

f = open('a.docx', 'rb')
doc = Document(f)

table = doc.tables[0]
data = []

keys = None
for i, row in enumerate(table.columns):
    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)

x = 0
for i in doc.paragraphs:
    if x < 20:
        print (i.text)
    else:
        break
    x = x + 1

f.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions