According to my understanding, workbook.get_sheet_names()
is deprecated and we should use wb.sheetnames
instead with openpyxl
2.6.2.
wb.sheetnames
returns a list
of all the sheets, so why can't we do this?
import openpyxl
wb=openpyxl.load_workbook('example.xlsx') #loading the workbook
wb.sheetnames #getting the sheetnames with the new recomended code
#output:['Sheet']
wb.sheetnames[0]='Another name'
wb.sheetnames[0] # Checking if it were changed or not
#output:['Sheet']
Why didn't the above code work if wb.sheetnames
acts as a list
?
No error was displayed but I didn't see the expected changes
This is what example.xls
looks like:
A B C 1 4/5/2015 13:34 Apples 73 2 4/5/2015 3:41 Cherries 85 3 4/6/2015 12:46 Pears 14 4 4/8/2015 8:59 Oranges 52 5 4/10/2015 2:07 Apples 152 6 4/10/2015 18:10 Bananas 23 7 4/10/2015 2:40 Strawberries 98