web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Automate - General Discussion
Unanswered

Run Script from SharePoint Library Fails with "The file format is not recognized" Error

(0) ShareShare
ReportReport
Posted on by 4

Dev Environment

I have a SharePoint Document Library (with full access) containing an Excel file. This Excel file is generated through a Power Automate flow, which populates tables using data from SharePoint lists.

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

  1. Requested the admin to enable Office Scripts for my user account.

  2. Created an Office Script in Excel Online.

  3. 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:

https://learn.microsoft.com/en-us/microsoft-365/admin/manage/manage-office-scripts-settings?view=o365-worldwide&source=recommendations

 https://community.powerplatform.com/forums/thread/details/?threadid=0c91f236-92e3-451b-910b-32852261a8de

 https://community.powerplatform.com/forums/thread/details/?threadid=ec37065d-84b8-ef11-b8e8-6045bddbcca5


 

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!

Categories:
I have the same question (0)
  • David_MA Profile Picture
    12,467 Super User 2025 Season 2 on at
    Run Script from SharePoint Library Fails with "The file format is not recognized" Error
    Please share a screen shot of the configuration of the action that runs the script. That will provide clues to your issue, but without being able to see it, we cannot tell if it is configured correctly.
  • AJSharma7274 Profile Picture
    4 on at
    Run Script from SharePoint Library Fails with "The file format is not recognized" Error
    Hi @David_MA 

    These are the screenshots from both environments — where it is failing (Dev) and where it is running successfully (Trial).
     
    • The Excel file shown below is on the Dev SharePoint site, and the script is written to delete sheets.
    • Excel file - Dev Env.png  
    • Power Automate flow (Dev) : 
    • Power Automate Flow - Dev Env.png
    • Ran Power Automate Flow  (Dev) :
    • Power Automate Flow Output - Dev Env.png
     
    • The Excel file shown below is on the Trial SharePoint site, and its script is the same as the one on Dev.
    • Excel file - Trial env.png
    • Power Automate flow (Trial) : 
    • Power Automate Flow - Dev Env.png
    • Ran Power Automate flow (Trail) : 
    • Power Automate Flow Output - Trial Env.png
    I hope this information is sufficient to analyze the problem.
     
  • David_MA Profile Picture
    12,467 Super User 2025 Season 2 on at
    Run Script from SharePoint Library Fails with "The file format is not recognized" Error
    I don't see any issues with what you've done. Maybe try this:
    1. After your trigger, use the Get file properties action and get the file.
    2. Then use the Identifier value from this action in the Run script action to specify the workbook.
    Maybe it will generate a different error message that will provide a better clue as to the issue. By chance, does this spreadsheet have macros in it and was it renamed from a .xlxm to .xlxs? If so, rename it to the correct extension or open the spreadsheet and do a Save As and then point your flow to the copy of the spreadsheet. Maybe the spreadsheet has become corrupted.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Automate

Last 30 days Overall leaderboard