属性错误:“工作簿"对象没有“活动"属性 [英] Attribute Error: 'Workbook' object has no attribute 'active'
问题描述
我对python编程和raspberry pi环境都是陌生的,我需要用它做一些项目.当我尝试为openpyxl库运行示例代码时,我发现自己陷入标题中提供的错误中:属性错误:工作簿"对象没有属性活动" 我尝试安装更多软件包,以检查是否仅缺少库,但它们都不起作用
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
推荐答案
检查正在运行的软件包的版本,因为它指出active
是该文档的最新版本中的属性.
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__)
您应该可以使用pip install openpyxl --upgrade
升级openpyxl版本以获得最新版本.
You should be able to upgrade your openpyxl version with pip install openpyxl --upgrade
to get the latest version.
这篇关于属性错误:“工作簿"对象没有“活动"属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!