getting the row and column numbers from coordinate value in openpyxl

前端 未结 5 1545
情深已故
情深已故 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:21

    What you want is openpyxl.utils.coordinate_from_string() and openpyxl.utils.column_index_from_string()

    from openpyxl.utils.cell import coordinate_from_string, column_index_from_string
    xy = coordinate_from_string('A4') # returns ('A',4)
    col = column_index_from_string(xy[0]) # returns 1
    row = xy[1]
    

提交回复
热议问题