使用python在excel表格中增加新的sheet表

方法一:使用xlutils.copy

import xlrd, xlwt
from xlutils.copy import copy as xl_copy

# open existing workbook
rb = xlrd.open_workbook('ex.xls', formatting_info=True)
# make a copy of it
wb = xl_copy(rb)
# add sheet to workbook with existing sheets
Sheet1 = wb.add_sheet('Sheet1')
wb.save('ex.xls')

方法二:使用openpyxl库

import openpyxl
wb=openpyxl.load_workbook(r'ex.xlsx')
wb.create_sheet(title='Sheet2',index=0)
wb.save(r'ex.xlsx')

猜你喜欢

转载自blog.csdn.net/zh54b5n64vn64654/article/details/81101681
今日推荐