Search code examples
pythonsmartsheet-api

How to extract all the values in a Smartsheet


I'm trying to extract data column-wise from a Smartsheet. I used the below code, but I'm getting row-wise values instead. How can I get it in column-wise format?

MySheet = ss_client.Sheets.get_sheet(Sheet_ID)
for MyRow in MySheet.rows:
    for MyCell in MyRow.cells:
        print(MyRow.id, MyCell.value)
    print('')

Solution

  • To add to what Software2 was saying, your code would look something like this:

    sheet_ID = xxxxxxxxxxxxxxxx
    col_id = xxxxxxxxxxxxxxxx
    
    MySheet = ss_client.Sheets.get_sheet(sheet_ID)
    
    for MyRow in MySheet.rows:
        for MyCell in MyRow.cells:
            if MyCell.column_id == col_id:
                if (MyCell.value):
                    print (MyRow.id, MyCell.value, MyCell.column_id)
        print('')