Using openpyxl to find rows that contain cell with specific value (Python 3.6)

前端 未结 4 2203
春和景丽
春和景丽 2021-02-10 16:24

I am completely new to openpyxl so, as you can imagine, I am having pretyy hard times when I try to make use of it.

I have an excel report that contains only one sheet

4条回答
  •  长情又很酷
    2021-02-10 16:46

    There's no need to use the pandas for this.

    from openpyxl import Workbook
    import openpyxl
    
    file = "enter_path_to_file_here"
    wb = openpyxl.load_workbook(file, read_only=True)
    ws = wb.active
    
    for row in ws.iter_rows("E"):
        for cell in row:
            if cell.value == "ABC":
                print(ws.cell(row=cell.row, column=2).value) #change column number for any cell value you want
    

提交回复
热议问题