Get Value Of Individual Cell Using Openpyxl
Solution 1:
Unless you're doing something more complicated than gathering some cells, numpy
or pandas
is usually unnecessary overhead. openpyxl
works well enough on its own.
You have two options for iterating through a worksheet but you're trying to mix them, hence the error.
One option is simply query every cell's value using the cell
method of the worksheet object with the row
and column
keyword arguments. The row
and column
indexes are 1-based integers, like this:
burndownData.cell(row=1, column=1).value
The other option is iterating the sheet and indexing the row as a list:
forrowin burndownData.iter_rows():
elemnt =row[0].value
This will get you column A of row 1, column A of row 2, and so on. (because it's an index of a Python list
it's zero-based)
What you were doing above:
for i in burndownData.iter_rows():
elemnt = burndownData.cell(row=i,column=1)
generates an error because i
is a tuple of openpyxl Cell
objects, and the row
argument to cell
expects an integer.
Update: I should add there's a third way to reference cells using the spreadsheet column:row
syntax, like this:
burndownData['B9'].value
but unless you're only going to select a few specific cells, translating back and forth between letters and numbers seems clumsy.
Post a Comment for "Get Value Of Individual Cell Using Openpyxl"