Reputation: 909
I'm bringing in data from another application, but I don't know what's new and what's updated, so I'm clearing the sheet (row by row - which is time intensive) and re-adding rows. I'd like to know if there is a way to clear the sheet with one command so that I can re-add my rows.
Keep in mind, My code is in C#. I do not know cURL or how to use it.
Upvotes: 0
Views: 239
Reputation: 873
There is no single command to delete all rows. However, you can specify a list of rows to delete. Here is some sample code.
var ss = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
var allColumns = ss.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
long primaryColumnId = (long) allColumns.Data.First(c => c.Primary == true).Id;
var columnsToRead = new long[] { primaryColumnId };
Sheet sheet = ss.SheetResources.GetSheet(sheetId, null, null, null, null, columnsToRead, null, null);
var rowsToDelete = sheet.Rows.Select(r => (long) r.Id);
ss.SheetResources.RowResources.DeleteRows(sheetId, rowsToDelete, true);
Notes:
To avoid reading the entire sheet, this sample determines the id for the primary column and only reads that single column.
If your sheet is huge and you get timeout errors on the delete, you will need to chunk the deletes. (Why? Deleting a row can trigger cascading changes due to cell links, formulas, etc.) If you encounter problems, please let me know and I can update the sample.
Upvotes: 3