Skip to content

Python-docx does not recognise/extract all table in docx #1015

@ghost

Description

Hi there, I am using python-docx 0.8.11 and Python 3.8. I want to get ALL tables contained in a relatively large word docx file. I am using this code:

dfs = []
for table in document.tables:
    df = [['' for i in range(len(table.columns))] for j in range(len(table.rows))]
    for i, row in enumerate(table.rows):
        for j, cell in enumerate(row.cells):
            if cell.text:
                df[i][j] = cell.text.replace('\n', '')
    dfs.append(pd.DataFrame(df))

However it seems that a lot of tables are not extracted.
Do you have any idea why that might be?
Thank you very much!

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