AttributeError: 'Worksheet' object has no attribute 'save'
时间: 2023-09-17 07:13:55 浏览: 361
This error occurs when you try to call the `save` method on a `Worksheet` object in Python, which does not have this attribute.
The `save` method is typically used with `Workbook` objects in the `openpyxl` library to save changes to an Excel file.
To fix this error, make sure you are calling the `save` method on a `Workbook` object, not a `Worksheet` object.
Here's an example of how to save changes to an Excel file using `openpyxl`:
```python
from openpyxl import Workbook
# create a new workbook object
wb = Workbook()
# select the active worksheet
ws = wb.active
# add some data to the worksheet
ws['A1'] = 'Hello'
ws['B1'] = 'World'
# save the changes to the workbook
wb.save('example.xlsx')
```
In this example, we create a new workbook object, select the active worksheet, add some data to it, and then call the `save` method on the `Workbook` object to save the changes to the file.
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)