Skip to content

Include cells wrapped in content controls during table traversal - #1630

Open
sunxiuguo wants to merge 1 commit into
python-openxml:masterfrom
sunxiuguo:fix-cell-sdt-traversal
Open

sunxiuguo wants to merge 1 commit into
python-openxml:masterfrom
sunxiuguo:fix-cell-sdt-traversal

Conversation

@sunxiuguo

Copy link
Copy Markdown

Summary

Fixes #689. Addresses the cell-level content-control part of #1489, not its separate cached field-text problem.

Word can wrap a complete table cell in w:sdt/w:sdtContent. Current traversal skips that cell, shifting extracted values into the wrong columns and sometimes making table.cell() select a cell from the following row.

  • Traverse cell-level content controls in document order, including nested wrappers, without descending into nested tables or accepting unrelated wrappers.
  • Use the same logical cells for row/table traversal, grid offsets, and vertical-merge lookup. Keep the generated direct-child tc_lst unchanged.
  • Reject merges whose rectangle intersects a wrapped cell before modifying XML. The existing merge implementation assumes direct sibling cells; crossing a content control could otherwise consume the wrong cell. Ordinary merges outside the control still work.
  • Add 22 regression cases and document the reading/merging boundary.

Validation

Linux, Python 3.12.14, lxml 6.1.1:

  • pytest -q: 1,631 passed, including all 22 new cases. Unchanged master: 1,609 passed; the new regression file fails against unchanged master.
  • Official behave --format progress --stop --tags=-wip: 67 features, 650 scenarios, 1,856 steps passed on both the final candidate and unchanged master.
  • Ruff check and format check passed for all three changed files.
  • Additional independent synthetic boundary checks: 302 passed, including reversed merge corners and XML unchanged on rejected merges.
  • Save/reopen → row/table/column extraction → pandas checks restore cell positions. Reading and resaving all 19 synthetic documents leaves document XML unchanged.

Pyright 1.1.401 reports no diagnostics in the changed files, but exits nonzero with one unused-ignore diagnostic in its bundled _typeshed/_type_checker_internals.pyi. The same diagnostic occurs on unchanged master; it has not been suppressed.

Scope

This does not add content-control authoring, cached fldSimple text extraction, or fix existing aggregate indexing for rows with omitted grid cells. No Word GUI/rendering or full multi-Python tox matrix was run.

AI-assisted implementation and review; the test results above were actually executed.

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

Successfully merging this pull request may close these issues.

Table cells with form fields seem to be parsed incorrectly

1 participant