A Alstone - 2 months ago 11

Python Question

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 corresponding row and column numbers to use for future operations, in the case row = 3, column = 3. I can get the row number easily using

`ws.cell('D4').row`

`4`

`ws.cell('D4').column`

`D`

Answer

What you want is `openpyxl.utils.coordinate_from_string()`

and `openpyxl.utils.column_index_from_string()`

```
from openpyxl.utils 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]
```