How to get excel sheet name in Python using xlrd

后端 未结 1 759
挽巷
挽巷 2021-01-04 19:22

Please see the code below.

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


        
1条回答
  •  -上瘾入骨i
    2021-01-04 20:13

    I have modified the code I gave as a question and have got what I needed actually,

    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)))
    

    so if the list (of tuple) pointSheetObj is iterated we have name of the sheet at index 1 of the tuple inside the pointSheetObj.

    By doing this I have got the name and the worksheet object with which I can carry on with other sheet related methods.

    0 讨论(0)
提交回复
热议问题