如何用python代码,将包含13个表的excel表格,按照各自表名,分为13个excel
时间: 2023-07-16 14:15:39 浏览: 38
可以使用Python中的pandas库来实现将包含13个表的Excel表格分为13个Excel文件。具体实现步骤如下:
1. 导入pandas库
```python
import pandas as pd
```
2. 使用pandas的read_excel函数读取包含13个表的Excel表格
```python
excel_file = pd.read_excel('file.xlsx', sheet_name=None)
```
3. 将读取的Excel表格按照各自的表名分别保存为13个Excel文件
```python
for sheet_name, sheet_data in excel_file.items():
sheet_data.to_excel(f"{sheet_name}.xlsx", index=False)
```
完整代码如下:
```python
import pandas as pd
# 读取包含13个表的Excel表格
excel_file = pd.read_excel('file.xlsx', sheet_name=None)
# 将读取的Excel表格按照各自的表名分别保存为13个Excel文件
for sheet_name, sheet_data in excel_file.items():
sheet_data.to_excel(f"{sheet_name}.xlsx", index=False)
```
注意:需要将file.xlsx替换为实际的Excel文件名,并且确保Excel文件与Python代码在同一目录下。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)