Introduction
Excel templates are commonly used in Power Automate to generate reports, export data, and refresh files with the latest information. In many scenarios, you need to clear the existing data from the Excel table before adding new records.
Although Power Automate provides actions to manage Excel data, deleting rows one at a time can be slow, especially when the table contains a large number of records.
A simple and efficient solution is to use Office Scripts in Excel Online. By running an Office Script from Power Automate, you can quickly remove all rows from an Excel table while keeping the table headers, formatting, and structure unchanged.
In this article, we will learn how to:
Check whether the Excel table exists.
Clear any active filters on the table.
Delete all existing rows.
Prepare the Excel template for inserting fresh data.
Prerequisites
Before starting, ensure the following:
The Excel file is stored in SharePoint or OneDrive for Business.
The data is stored inside an Excel Table.
You have access to Excel Online (Business).
You have access to Power Automate.
Sample Scenario
Suppose you have an Excel template named:
Excle_PowerShellBulkData.xlsx
The workbook contains a table named:
Table1
Every time your Power Automate flow runs, you want to:
Remove all existing rows.
Keep the table headers and formatting.
Insert fresh data from SharePoint or another data source.
Why Use Office Scripts?
Using Office Scripts provides several benefits:
Faster than deleting rows one by one.
Keeps the table structure intact.
Easy to integrate with Power Automate.
Suitable for large datasets.
Prevents issues caused by filtered rows.
Why Clear Filters Before Deleting Rows?
Sometimes users apply filters manually in Excel or the file may already contain filtered data from previous executions.
If filters remain active, the script may:
Fail to delete all rows.
Delete only visible rows.
Return an error during execution.
To avoid these issues, it is recommended to clear all filters before deleting rows.
Create the Office Script
Open the Excel file in Excel Online and follow these steps:
Open the workbook.
Select the Automate tab.
Click New Script.

Replace the default code with the following script.

Join the conversation! Your thoughts help the community grow.