Xlsxwriter order worksheets with a specified order
Asked Answered
F

1

5

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)
Flavius answered 16/3, 2016 at 14:3 Comment(5)
so why does your lambda function not work?Polariscope
The lamba does work but it's an alphabetical order. I want to specify the order with for example a list.Flavius
Use a different function, like this : lambda x: sheetlist.index(x.name)Adytum
I'm assuming it's getting the index from my list and using that as the order value? I'm not really good with lambdas.Flavius
@Adytum Thanks, that was easier than I actually expected. Gonna have to study the lambdas a bit again. You can use your comment as the answer otherwise I'll do it later.Flavius
A
7

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.

Adytum answered 16/3, 2016 at 15:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.