2017-11-02 7 views
0

以下は私のコードです。私は特定の 'cell'要素のrowidcolumnidをキャプチャしようとしていますが、行名と列名を使用してExcelシートのセル値をキャプチャしようとしていますが、キャプチャできません。pythonで行と列の名前を使用して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 "***************" 

助けが必要ですか?

答えて

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) 
関連する問題