程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python xlrd splits the workbook sheet of the same excel table into multiple xlsx sheets named sheetname

編輯:Python
# -*- coding: utf-8 -*-
import xlrd
from openpyxl import Workbook
# Change to the name of the table you want to split 
wb = xlrd.open_workbook(" Output one by one ( Shanghai and Shenzhen stocks ).xls")
sheetnames = wb.sheet_names()
print("sheetnames",sheetnames)
# Traverse sheet
for name in sheetnames:
ws = wb.sheet_by_name(name)
# Create a new excel surface 
wb2 = Workbook()
# Get current sheet
ws2 = wb2.active
# Traverse excel Table contents and write new excel surface 
for i, row in enumerate(ws.get_rows()):
for j, cell in enumerate(row):
# Write new Excel
ws2.cell(row=i + 1, column=j + 1, value=cell.value)
# Set new Sheet The name of 
ws2.title = name
wb2.save(name + ".xlsx")

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved