getting sheet names from openpyxl

谁都会走 提交于 2019-12-02 17:55:10
alecxe

Use the sheetnames property:

sheetnames

Returns the list of the names of worksheets in this workbook.

Names are returned in the worksheets order.

Type: list of strings

print (wb.sheetnames)

You can also get worksheet objects from wb.worksheets:

ws = wb.worksheets[0]

As mentioned the earlier answer you can get the list of sheet names by using the ws.sheetnames

But if you know the sheet names you can get that worksheet object by

ws.get_sheet_by_name("YOUR_SHEET_NAME")

Another way of doing this is as mentioned in earlier answer

ws['YOUR_SHEET_NAME']

python 3.x for get sheet name you must use attribute

g_sheet=wb.sheetnames

return by list

for i in g_sheet:
    print(i)

**shoose any name **

ws=wb[g_sheet[0]]

or ws=wb[any name] suppose name sheet is paster

ws=wb["paster"]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!