使用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')

 

你可能感兴趣的:(python)