[Python] Missing spaces between words when parsing with python-docx

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    python-docx has a very simple object model: Document -* Paragraph -* Run, and is very easy to work with.

    However there's one showstopper issue: in some cases consequent runs (e.g. single words) do not contain any whitespace, yet the paragraph.text attribute contains whitespace between said runs.

    This is a major headache, because I have to concatenate a subset of runs based on their color and style properties, and filter out the rest. Because of the issue, some words get crammed together.

    I tried inserting spaces and then removing redundant whitespace at the end, but it proved to be a very error prone approach.

    Has anyone stumbled upon this? Any suggestions would be very appreciated.

    Continue reading...

Compartilhe esta Página