Reputation: 49
I'm having an issue retrieving the cell values of multiple columns in specific rows from two different worksheets. I'm attempting to iterate through the first column of two worksheets, which hold unordered key values. Once I iterate through all key values and find the cell location of the matching values in the two worksheets, I call my def column_name function to iterate through a range of columns for that specific key value(the row cell is passed as a parameter into my function; indicated by uniqueID). [m1 and worksh1] and [m2 and worksh2] represent sheets in the workbook. If anyone can help me resolve the following error, I'd greatly appreciate it. This error appears on the first line of my column_name function.
for col_cells in workbk1.iter_cols(min_row=uniqueID,max_row=uniqueID,min_col=start,max_col=last):
Error: >File C:...\Python39\site-packages...openpyxl\worksheet\worksheet.py, line 516, in _cells_by_col for row in range(min_row, max_row+1). TypeError: unsupported operand type(s) for +: 'Cell' and 'int'
def column_name(workbk1, workbk2, uniqueID):
for col_cells in workbk1.iter_cols(min_row=uniqueID,max_row=uniqueID,min_col=start,max_col=last):
for cell in col_cells:
for col_cells2 in workbk2.iter_cols(min_row=uniqueID,max_row=uniqueID,min_col=start2,max_col=last2):
for cell2 in col_cells2:
[execute code]
Upvotes: 0
Views: 189
Reputation: 19861
In column_name
function the last argument is uniqueID
which is passed to min_row
and max_row
. It means that the unqiueID
should be an integer. But when calling the function, it is being called as column_name(m1,m2,cell)
where we are passing the actual cell
object as uniqueID
.
Later in openpyxl when it tries max_row+1
, it fails with following error because max_row
is actually a Cell
:
TypeError: unsupported operand type(s) for +: 'Cell' and 'int'
Upvotes: 1