Now, I have a requirement to remove any Excel sheets that do not contain data. I decided to use Office Scripts to handle this. Here are the steps I've taken so far
-
Requested the admin to enable Office Scripts for my user account.
-
Created an Office Script in Excel Online.
-
Built a manual Power Automate flow for testing purposes.
In the flow, I added the following steps:
-
Manual trigger
-
Run script action (selected SharePoint site, document library, Excel file, the script, and passed input parameters)
However, I encountered the following error:
"The file format is not recognized. Please check that the selected workbook is valid."
​ 

Office Script :
function main(workbook: ExcelScript.Workbook, sheetNamesToDelete: string[]) {
const existingSheets = workbook.getWorksheets().map(sheet => sheet.getName());
for (let sheetName of sheetNamesToDelete) {
if (existingSheets.includes(sheetName)) {
const sheet = workbook.getWorksheet(sheetName);
sheet.delete();
}
}
}
I also tried using the alternative action "Run script from SharePoint library", but I received the same error.
Interestingly, when I moved the same Excel file to OneDrive, the Power Automate flow ran successfully. This issue seems to occur only when the Excel file is located in the SharePoint Document Library.
The blogs below also didn’t work:
Test Environment (Trial Tenant)
In the trial environment, I created a new SharePoint site and document library, then uploaded the same Excel file. I recreated the same Power Automate flow, used the same script, and it executed successfully without errors.
I’m unable to identify what additional permissions or configurations might be required to run Office Scripts successfully in the Dev environment.
Any insights or suggestions would be appreciated!