You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Failed to read the entire text of a cell in a table #1390
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.
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.
Activity
Chenhong-Zhang commentedon May 8, 2024
test.docx
scanny commentedon May 18, 2026
This is because that text is wrapped in a
w:smartTagelement, 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 thereforecell.text) in a future version.