Skip to content

Failed to read the entire text of a cell in a table #1390

Open

Description

@Chenhong-Zhang

I was iterating over the tables, and extracting the text in each cells. Most of the time the following code works perfectly:

for object in document.iter_inner_content():
    if type(object)==docx.table.Table:
        for row in object.rows:
            for cell in row.cells:
                print(cell.text)

But in some special occasions, especially when there are numbers in the cells' text, the cell.text command failed to extract the entire text. For example the original cell include the text like this:

【24#梁南侧腹板近1#台处,多处箍筋锈蚀、混凝土剥落,0.2×0.5m。】

The cell.text command would return a string like this:

【24#梁南侧腹板近1#台处,多处箍筋锈蚀、混凝土剥落,0.2×。】

As you can see, the "0.5m" was missing in the extracted text. But the period and the right bracket was extracted, so I suppose it is not because of truncation occurred in the string.

I think this is a bug. The file which I tested the bug is attached to this issue.

Activity

  1. Chenhong-Zhang commented on May 8, 2024

    @Chenhong-Zhang
    Author
  2. scanny commented on May 18, 2026

    @scanny
    Contributor

    This is because that text is wrapped in a w:smartTag element, which was a legacy precursor to structured data tags (SDT) and used for automatically filling in values from an external source like a database or XML file when generating documents.

    We might include such text in paragraph.text (and therefore cell.text) in a future version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions