[Python] openpyxl on Windows 10, Pycharm, consistently giving "TypeError: __init__() got an...

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm completely stuck. I'm a novice at Python, running Pycharm. I've tried various iterations of code involving openpyxl, coming to the conclusion that I've done something wrong and cannot for the life of me get openpyxl to run properly. I've installed the package openpyxl and with the below code, I always get an error. I'm on Windows 10 and have replicated this error across two of my devices. Code:

    import openpyxl
    from openpyxl import load_workbook

    workbook = load_workbook('MYDIRECTORY/FILENAME.xlsx') # but I actually use proper path and name
    sheet = workbook['PupilList'] # The name of my sheet
    cell_value = sheet['A1'].value
    print(cell_value)


    Pretty basic, but even this throws up (as does all my other code involving this or pandas) the following error:

    C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\Scripts\python.exe C:\Users\ExamUser\PycharmProjects\pythonProject1\main.py
    Traceback (most recent call last):
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\main.py", line 5, in <module>
    workbook = load_workbook('C:/Users/ExamUser/Desktop/StudentDataCompiler/PupilList.xlsx') # Replace 'your_file.xlsx' with the actual file path
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
    reader.read()
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\reader\excel.py", line 299, in read
    apply_stylesheet(self.archive, self.wb)
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 198, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\styles\stylesheet.py", line 103, in from_tree
    return super(Stylesheet, cls).from_tree(node)
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
    File "C:\Users\ExamUser\PycharmProjects\pythonProject1\venv\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
    return cls(**attrib)
    TypeError: __init__() got an unexpected keyword argument 'xxid'

    Process finished with exit code 1



    Can anyone tell me how to fix this? I'm extremely grateful for any help you can share.

    I've tried different installs of python (3.9, the lastest, 3.8: all same result); I've tried fully uninstalling both python and pycharm, then reinstalling them. No joy.

    Continue reading...

Compartilhe esta Página