To find Python openpyxl value coordinates

Asked 1 years ago, Updated 1 years ago, 519 views

I read the Excel file in openpyxl I'd like to find the cell coordinates of the value written in the excel I don't know what code to use even if I try hard to google.

python openpyxl

2023-01-02 15:24

1 Answers

By default, to use openpyxl, you can read the file, specify the sheet, and then read or specify the value in Sheet["A1"].

    excel = openpyxl.Workbook()
    sheet = excel['Sheet']

    a = "hello"
    sheet["A1"] = f"{a} world"
    print(sheet["A1"].value)

If you find the coordinate value of the cell with the value of hello world, I am not sure how to find it as a double for statement.

    excel = openpyxl.Workbook()
    sheet = excel['Sheet']

    a = "hello world"
    for i in range(1, 100):
        For j in range('A'-'ZZ'): # Col value is alphabets, so I think you need to implement this part.
            if sheet[f'{i}{j}'].value == a:
                return [i, j]


2023-01-02 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.