I have a table on a spreadsheet and I want to delete all the existing data. I use the code below which works except when the table is already empty.
// Get the row count
let rowCount = table.getRangeBetweenHeaderAndTotal().getRowCount();
// Delete all the rows
table.deleteRowsAt(0,rowCount);
The problem is that rowCount will return 1 even if the table is empty. When deleteRowsAt
tries to delete a row in an empty table it returns an error.
In VBA we can use table.ListRows.Count
and this will return 0 if the table is empty.
Example: I have 3 rows in the table
If I select all the rows and delete them from the Table I get this:
This table now has no rows but I have no way to get this result. As I said, in VBA we would use table.ListRows.Count
and this would return 0 but I cannot seem to find the equivalent for Office Scripts.