I'm trying to use the Smartsheet Python SDK to find cells that match a certain displayValue
. My cells look something like this:
{"columnId": 6xxxx6xxxx4xxxx8, "displayValue": "John Jacob", "value": "John Jacob"}
I want to print all cells whose columnId
== participantColumnID
AND displayValue
== participantNumber
. Unfortunately, I have no idea how to access the Cell attributes and the API docs don't describe how to access them either. Any help much appreciated.
smartsheet_client = smartsheet.Smartsheet(access_token)
sheet = smartsheet_client.Sheets.get_sheet(sheet_id)
participantColumnID = "30xxxxxxxxxx2452"
participantNumber = "12345"
for row in sheet.rows:
for cell in row.cells:
if cell.columnId == participantColumnID:
if cell.displayValue == participantNumber:
print(cell)
Note that I've also tried accessing via subscript cell[0]
and cell[columnId]
and that doesn't work either. <class 'smartsheet.models.cell.Cell'> is not subscriptable.
TypeError: 'Cell' object is not subscriptable
I'm not very familiar with Python or with the Smartsheet Python SDK -- but could your problems be caused by the fact that you're using invalid Cell
property names in your code?
Seems like the integration tests (for rows) within the SDK repo in GitHub shows how to reference Cell
properties when using the Python SDK. For example, I see this code there (lines 105-108)
for row in sheetb.rows:
ids.append(row.id)
for cell in row.cells:
column_ids.append(cell.column_id)
Comparing that code with the code you've posted in your question above, one thing that jumps out at me is that you're using cell.columnId
whereas the integration test uses cell.column_id
. Likewise, I suspect that where you're using cell.displayValue
-- it should instead be cell.display_value
. (See the definition for the Cell
object in the SDK for a complete list of all property names in the Cell
object.)