Python 如何使用XLRD获取特定行中特定列中的值

Python 如何使用XLRD获取特定行中特定列中的值,python,xlrd,Python,Xlrd,我试图循环浏览电子表格,并获取某列下某行中某个单元格的值,如下所示: # Row by row, go through the originalWorkSheet and save the values from the selected columns numberOfRowsInOriginalWorkSheet = originalWorkSheet.nrows - 1 rowCounter = 0 while rowCounter <= numberOfRowsInOriginal

我试图循环浏览电子表格,并获取某列下某行中某个单元格的值,如下所示:

# Row by row, go through the originalWorkSheet and save the values from the selected columns
numberOfRowsInOriginalWorkSheet = originalWorkSheet.nrows - 1
rowCounter = 0
while rowCounter <= numberOfRowsInOriginalWorkSheet:
    row = originalWorkSheet.row(rowCounter)
    #Grab the values in certain columns, say with the 
    # column name "Promotion" and save them to a variable
#逐行查看原始工作表并保存所选列中的值
NumberOfRowSinoOriginalWorksheet=原始工作表.nrows-1
行计数器=0

rowCounter有很多方法可以做到这一点,请查看

大概是这样的:

promotion_col_index = <promotion column index>

list_of_promotion_cells = originalWorkSheet.col(promotion_col_index)

list_of_promotion_values = [cell.value for cell in list_of_promotion_cells]
promotion\u col\u index=
提升单元格列表=原始工作表.col(提升列索引)
提升单元列表值=[提升单元列表中单元的cell.value]
将在“升级”列中为您提供一个值列表,最简单的方法是:

from xlrd import open_workbook


book = open_workbook(path_to_file)
sheet = book.sheet_by_index(0)
for i in range(1, sheet.nrows):
    row = sheet.row_values(i)
    variable = row[0]  # Instead zero number of certain column
也可以循环行列表并打印每个单元格值

book = open_workbook(path_to_file)
sheet = book.sheet_by_index(0)
for i in range(1, sheet.nrows):
    row = sheet.row_values(i)
    for cnt in range(len(row)):
       print row[cnt]

希望这有帮助

这成功了,非常感谢!Python对我来说是新事物,我目前处于自我教育模式,这有助于澄清一些事情。谢谢!