Skip to content

WD_PARAGRAPH_ALIGNMENT EXTENTION #1473

@yanedev

Description

@yanedev

ValueError: WD_PARAGRAPH_ALIGNMENT has no XML mapping for 'start'

Is it possible to add on existing (left, center, right) the start and end mappings so that this error is avoided. If I'm correct it should be added in the

class WD_PARAGRAPH_ALIGNMENT(BaseXmlEnum):
    LEFT = (0, "left", "Left-aligned")
    """Left-aligned"""

    CENTER = (1, "center", "Center-aligned.")
    """Center-aligned."""

    RIGHT = (2, "right", "Right-aligned.")
    """Right-aligned."""
...

like

END = (0, "left", "Left-aligned")

or

LEFT = (0, "left", "Left-aligned", "start")

Activity

yanedev

yanedev commented on Feb 26, 2025

@yanedev
Author

probably not that easy but worth a try

yanedev

yanedev commented on Feb 26, 2025

@yanedev
Author

I've managed to avoid it with the code bellow, if anyone else has similar problems. It's not the best but it works in my case

try:
    new_cell.paragraphs[0].alignment = cell.paragraphs[0].alignment
except Exception as e:
    error_msg = str(e)
    if "start" in error_msg:
        new_cell.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    elif "end" in error_msg:
        new_cell.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
    else:
        print(error_msg)
zjk000

zjk000 commented on Jun 16, 2025

@zjk000

I've managed to avoid it with the code bellow, if anyone else has similar problems. It's not the best but it works in my case

try:
    new_cell.paragraphs[0].alignment = cell.paragraphs[0].alignment
except Exception as e:
    error_msg = str(e)
    if "start" in error_msg:
        new_cell.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
    elif "end" in error_msg:
        new_cell.paragraphs[0].alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
    else:
        print(error_msg)

Works like a charm.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zjk000@yanedev

        Issue actions

          WD_PARAGRAPH_ALIGNMENT EXTENTION · Issue #1473 · python-openxml/python-docx