使用python

时间:2017-11-02 08:41:33

标签: python-2.7 xlrd

以下是我的代码。我试图捕获特定“'”小区的rowidcolumnid。元素和使用行名称和列名称的Excel工作表中的单元格值,但我无法捕获它。

    from xlrd import open_workbook
    book = open_workbook("D:\A2.xlsx")
    for sheet in book.sheets():
        for rowidx in range(sheet.nrows):
            row = sheet.row(rowidx)
            for colidx,cell in enumerate(row):
                if cell.value == "PES":#row value
                   print "Found Row Element"
                   for column in range(sheet.ncols):
                       col = sheet.col(column)
                       for rowid,cell1 in enumerate(col):
                           if cell1.value == "# Responses PCSAT YTD":#column value
                           print rowidx,colidx
                           print "Column Element Found"
                           print sheet.name
                           print (sheet.cell1(rowidx,colidx).value)#must be cell value
                           print "***************"

任何帮助?

1 个答案:

答案 0 :(得分:0)

这是你想要的吗?

from xlrd import open_workbook
book = open_workbook("book.xlsx")
for sheet in book.sheets():
    for rowidx in range(sheet.nrows):
        row = sheet.row(rowidx)
        for colidx,cell in enumerate(row):
            if cell.value == "PES":#row value
               print ("Found Row Element")
               print(rowidx, colidx)