AttributeError: 'Workbook' object has no attribute 'active'
时间: 2023-09-03 19:06:40 浏览: 253
AttributeError: 'Workbook' object has no attribute 'active' 这个错误是因为你尝试访问Workbook对象的active属性,但是Workbook对象没有该属性。根据引用的内容,你可能是在尝试使用Workbook对象的add_sheet()方法创建工作表。然而,这个方法已经被弃用,所以你需要使用其他方法来创建工作表。可以使用Workbook对象的create_sheet()方法来创建新的工作表。例如,你可以使用以下代码创建一个名为"Sheet1"的工作表:
```
import openpyxl
# 创建一个新的工作簿
wb = openpyxl.Workbook()
# 创建一个名为"Sheet1"的工作表
sheet = wb.create_sheet("Sheet1")
# 访问工作表
print(sheet.title)
```
这样就可以创建一个工作表并访问它的标题。希望这个解决方案能帮助到你。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python在同一个excel中写入多张表.AttributeError:’Workbook’ object has no attribute ‘add_sheet](https://blog.csdn.net/Viola_Ma/article/details/120458528)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [关于AttributeError: ‘Workbook‘ object has no attribute ‘get_active_sheet‘的问题已解决](https://blog.csdn.net/m0_72306909/article/details/130680586)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [python报错: list object has no attribute shape的解决](https://download.csdn.net/download/weixin_38748721/13708867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文