Attribute Error: 'Workbook' object has no

2019-08-30 09:56发布

问题:

I am new to both python programming and the raspberry pi environment and I need to do some project with it. As I was trying to run the sample code for the openpyxl library I found myself stuck in the error provided in the title, Attribute Error: 'Workbook' object has no attribute 'active' I tried to install some more packages to check if there are just missing libraries but none of them work

the code I am trying is below:

    from openpyxl import Workbook
    wb = Workbook()
    ws = wb.active
    ws['A1'] = 42
    ws.append([1, 2, 3])
    import datetime
    ws['A2'] = datetime.datetime.now()
    wb.save("sample.xlsx")

how can I get to run it? thanks in advance

回答1:

Check the version of the package you're running as it states that active is a property in the latest version of the documentation.

To discover your current version:

import openpyxl
print(openpyxl.__version__)

You should be able to upgrade your openpyxl version with pip install openpyxl --upgrade to get the latest version.