700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > python拆分excel的sheet为单文件_Python 3实现把各个Sheet另存为单独的Excel

python拆分excel的sheet为单文件_Python 3实现把各个Sheet另存为单独的Excel

时间:2020-02-19 02:11:33

相关推荐

python拆分excel的sheet为单文件_Python 3实现把各个Sheet另存为单独的Excel

# -*- coding: utf-8 -*-

# @Time : /1/16 12:55

# @Author : Philly

# @File : sdsd.py

# @Description: 把各个Sheet另存为单独的Excel

from openpyxl import load_workbook,Workbook

wb = load_workbook("Sheet.xlsx")

sheetnames = wb.sheetnames

for name in sheetnames:

ws = wb.get_sheet_by_name(name)

print(ws)

# 创建新的Excel

wb2 = Workbook()

# 获取当前sheet

ws2 = wb2.active

#两个for循环遍历整个excel的单元格内容

for i,row in enumerate(ws.iter_rows()):

for j,cell in enumerate(row):

# 写入新Excel

ws2.cell(row=i+1, column=j+1, value=cell.value)

# 设置新Sheet的名称

ws2.title = name

wb2.save(name + ".xlsx")

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。