openpyxl 打开excel
时间: 2023-08-24 07:15:00 浏览: 79
python操作word,excel,pdf.pdf
使用openpyxl模块打开Excel文件的代码如下:
```python
import openpyxl
# 打开Excel文件
workbook = openpyxl.load_workbook('example.xlsx')
# 打开第一个工作表
worksheet = workbook.worksheets\[0\]
```
在这段代码中,`openpyxl.load_workbook()`方法用于打开一个Excel文件,并返回一个Workbook对象。然后,我们可以使用`workbook.worksheets\[0\]`来打开第一个工作表。\[2\]
#### 引用[.reference_title]
- *1* [openpyxl操作excel](https://blog.csdn.net/qq_32708671/article/details/129936017)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [请用openpyxl 打开excel文件,并打开第一个工作表](https://blog.csdn.net/weixin_42576804/article/details/129617689)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文