Colin Gan
Colin Gan

Reputation: 21

using openpyxl copy worksheet from the first sheet, then rename them with name which in a list

I have a name tuple and I have a template worksheet. Now I want to copy the first worksheet, the times of copy are the number of the names (in the tuple), and the copied worksheets are renamed with all the names

wBookTongJi = openpyxl.load_workbook('D:\\example.xlsx')
tupleRequestStaff = ['Ross', 'Joy', 'Monica']

# from this I don't know how to code
for i in listRequestStaff
wBookTongJi.copy_worksheet(wBookTongJi['Sheet1']).title=...

Upvotes: 0

Views: 2697

Answers (1)

Colin Gan
Colin Gan

Reputation: 21

just figure out my own problem

tupleRequestStaff=('Ross', 'Richul', 'Joy')
for i in range(len(tupleRequestStaff)):
    wBookTongJi.copy_worksheet(wBookTongJi['Sheet1']).title = 
    tupleRequestStaff[i]
    wBookTongJi.save('D:\\Users\\6-7.xlsx')
wBookTongJi.remove(wBookTongJi['Sheet1'])
wBookTongJi.save('D:\\Users\\6-7.xlsx')

Upvotes: 1

Related Questions