getting the row and column numbers from coordinate value in openpyxl

前端 未结 5 1553
情深已故
情深已故 2020-12-07 20:55

I\'m trying to covert a coordinate value in excel to a row number and column number in openpyxl.

For example if my cell coordinate is D4 I want to find the correspon

5条回答
  •  伪装坚强ぢ
    2020-12-07 21:24

    You could just use pure Python:

    cell = "D4"
    col = ord(cell[0]) - 65
    row = int(cell[1:]) - 1
    

    This uses the ord function which takes a character and returns its ASCII code. In ASCII the letter A is 65, B is 66 and so on.

提交回复
热议问题