how to delete all the rows of a sheet using python at once

I am trying to build an automation that updates an excel file to smartsheet once I run it.

I have build that program but issue i am facing is that they are getting updated below the previous one. So I want to delete the rows first .Is there any way to do it without requiring row id.?

Best Answer

  • Chre Teitelbaum
    edited 02/18/22 Answer ✓

    There doesn't seems to be a way for bulk deletion through the API without using row ids. I handle this by using a function similar to the one below, prior to uploading new rows. Depending on how many rows are in your sheet, you may have to do it in chunks because you may not be able to fit all the row ids in the URL. I have found chunks of 300 row ids to be the largest.

    def delete_existing_data(sheet, chunk_interval=300):
        rows_to_delete = [row.id for row in sheet.rows]
        for x in range(0, len(rows_to_delete), chunk_interval):
            smart.Sheets.delete_rows(sheet.id, rows_to_delete[x:x + chunk_interval])
    

    Is there a reason you can't use the row id?

Answers