title: How to delete all rows in a table using Office Scripts
body: <p>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.</p>
  <pre><code>// Get the row count
  let rowCount = table.getRangeBetweenHeaderAndTotal().getRowCount();
  
  // Delete all the rows
  table.deleteRowsAt(0,rowCount);
  </code></pre>
  <p>The problem is that rowCount will return 1 even if the table is empty. When <code>deleteRowsAt</code> tries to delete a row in an empty table it returns an error.</p>
  <p>In VBA we can use <code>table.ListRows.Count</code> and this will return 0 if the table is empty.</p>
  <p>Example: I have 3 rows in the table
  <a href="https://i.stack.imgur.com/2IDvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2IDvf.png" alt="enter image description here" /></a></p>
  <p>If I select all the rows and delete them from the Table I get this:
  <a href="https://i.stack.imgur.com/3UUUq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3UUUq.png" alt="enter image description here" /></a></p>
  <p>This table now has no rows but I have no way to get this result. As I said, in VBA we would use <code>table.ListRows.Count</code> and this would return 0 but I cannot seem to find the equivalent for Office Scripts.</p>