[Python] Unexpected Sheet Renaming in OpenPyXL When Only Case Changes

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using OpenPyXL in Python to manipulate Excel workbooks. I encountered an unexpected behavior when renaming a sheet. If I change the name of a sheet to a name that only differs in letter case from its previous name, OpenPyXL appends a '1' to the new name.

    Here is a Minimal Reproducible Example:

    import openpyxl
    # Create a new workbook
    wb = openpyxl.Workbook()
    # Get the default sheet
    sheet = wb.active
    # Rename the sheet to 'Input (Raw)'
    sheet.title = 'Input (Raw)'
    # Rename the sheet to 'Input (raw)'
    sheet.title = 'Input (raw)'
    # Print the current title of the sheet
    print(sheet.title)


    Expected Output:

    Input (raw)


    Actual Output:

    Input (raw)1


    I'm using Python 3.11.1 and openpyxl 3.1.2.

    Continue reading...

Compartilhe esta Página