Search code examples
pythontypeerroropenpyxl

I'm trying to use OPENPYXL, I get this TYPE ERROR whenever i try to create an excel file


I am learning from Youtube, even if I copy the same code that runs on his screen I get the error. Even if I copy other solutions from the internet I get the same error whenever the program wants to create an excel file.

from openpyxl import workbook

wb=workbook()
ws=wb.active
ws.title="Sheet-1"

ws['A1']="Simple data"

wb.save("too_bad.xlsx")

I have a gut feeling that this code is only faulty on my computer. I hope this gut is wrong


Solution

  • Python modules are type-sensitive, so it makes a difference if you use "workbook" or "Workbook". The bellow code should work now.

    from openpyxl import Workbook
    
    wb=Workbook()
    ws=wb.active
    ws.title="Sheet-1"
    
    ws['A1']="Simple data"
    
    wb.save("too_bad.xlsx")