xlwings新建sheet
时间: 2023-08-08 16:04:43 浏览: 131
AST2600 Datasheet
使用xlwings库可以在Excel中新建sheet。可以使用以下代码来实现:
```python
import xlwings as xw
# 启动Excel程序
app = xw.App(visible=True, add_book=False)
# 打开Excel文件
wb = app.books.open('your_file_path.xlsx')
# 新建一个sheet
new_sheet = wb.sheets.add()
# 保存工作簿
wb.save()
# 关闭工作簿
wb.close()
# 退出Excel程序
app.quit()
```
以上代码会在已有的Excel文件中新建一个sheet,并保存工作簿。最后关闭工作簿和退出Excel程序。你可以根据需要修改文件路径和新建sheet的名称。
#### 引用[.reference_title]
- *1* [Python(Python+Qt)学习随笔:使用xlwings新建Execl文件和sheet的方法](https://blog.csdn.net/LaoYuanPython/article/details/102960441)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Python使用xlwings创建新的Excel工作簿文件](https://blog.csdn.net/weixin_43050480/article/details/122868107)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [自动化办公 02_1 Excel_XLWings](https://blog.csdn.net/weixin_46847902/article/details/125695047)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文