How to get excel sheet name in Python using xlrd

Please see the code below.

def getSheetName(file_name):
    pointSheetObj = []
    import xlrd as xl
    TeamPointWorkbook = xl.open_workbook(file_name)
    pointSheets = TeamPointWorkbook.sheet_names()

    for i in pointSheets:
        pointSheetObj.append(TeamPointWorkbook.sheet_by_name(i))

I need to get the name of an excel sheet name from a list pointSheetObj, iterating it.

+4
source share
1 answer

I changed the code that I gave as a question and got what I really needed,

def getSheetName(file_name):
    pointSheetObj = []
    import xlrd as xl
    TeamPointWorkbook = xl.open_workbook(file_name)
    pointSheets = TeamPointWorkbook.sheet_names()

    for i in pointSheets:
        pointSheetObj.append(tuple((TeamPointWorkbook.sheet_by_name(i),i)))

therefore, if list ( tuple) is pointSheetObjiterated, we have the name of the sheet index 1 tupleinside pointSheetObj.

Having done this, I have a name and worksheet with which I can continue to use other methods related to sheets.

+3
source

Source: https://habr.com/ru/post/1544286/


All Articles