Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 406
Adrian Z. Avatar asked Mar 16 '16 14:03

Adrian Z.


1 Answers

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.

like image 80
alpha1554 Avatar answered Oct 17 '22 04:10

alpha1554