Skip to content

Cells with field values/drop down menu in word is not recognised as text with _Cells.text #1489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Heikasee opened this issue May 16, 2025 · 0 comments

Comments

@Heikasee
Copy link

Heikasee commented May 16, 2025

For cells with a field code or a drop down menu, the library does not recognise the text within them.

For example, here is a word table with the first row having dropdown menus, second row having field values and third row just having normal text

Image

Running through the code below

from docx import Document
import pandas as pd

doc = Document("C:\Developer\example\exampletable.docx")
tables = []
for table in doc.tables:
    # initialise df
    df = [['' for _ in range(len(table.columns))] for _ in range(len(table.rows))]
    
    # populate the df with data from table
    for i, row in enumerate(table.rows):
        for j, cell in enumerate(row.cells):
            df[i][j] = cell.text
    
    tables.append(pd.DataFrame(df))
    
print(tables[0])

results in this table

             0       1
0     Dropdown
1  Field value
2  Normal Text  Hello

Here is the files for the above example: example.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant