Adrian Z.
Adrian Z.

Reputation: 934

Xlsxwriter order worksheets with a specified order

I would like to order my worksheets in a specific order (not alphabetical). In the past I have used Pandas DataFrame that was followed by a list.

DataFrame(csv_dict_list)[self.ORDER_LIST]

Right now I have to use the workbook and worksheet methods to create my worksheets. I have found out that you can call all worksheets by using workbook.worksheets() or worksbook.worksheets_objs() but I can't use a list there. Only lamba (I think) like this

workbook.worksheets_objs.sort(key=lambda x: x.name)

Upvotes: 5

Views: 3206

Answers (1)

alpha1554
alpha1554

Reputation: 605

Use a different lambda function, like this : lambda x: sheetlist.index(x.name). Lambdas inherit the scope in which they are called, so they can reference lists that are created in their 'parent' scope.

Upvotes: 7

Related Questions