如何使用 xlrd 在 Python 中获取 Excel 工作表名称 [英] How to get excel sheet name in Python using xlrd
本文介绍了如何使用 xlrd 在 Python 中获取 Excel 工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请看下面的代码.
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))
我需要通过迭代从列表 pointSheetObj
中获取 Excel 工作表名称的名称.
I need to get the name of the excel sheet name from the list pointSheetObj
by iterating it.
推荐答案
我已经修改了我作为问题给出的代码,并得到了我真正需要的,
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)))
所以如果列表(tuple
)pointSheetObj
被迭代,我们在tuple 的
在 index 1
处有工作表的名称pointSheetObj
内.
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.
这篇关于如何使用 xlrd 在 Python 中获取 Excel 工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文