cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ManasKumar01
Regular Visitor

Getting Error "The file format is not recognized. Please check that the selected workbook is valid." while running a office script in power automate

Hi All,
I am trying to save the email attached excel file to share point library and then running a office script to extract the data from newly created excel file. But  while running the "Get data from a file" office script getting below error
"The file format is not recognized. Please check that the selected workbook is valid."
I have modified and used "Get attachment V2" to create excel file  and manually ran the "Get data from a file" action in which it runs office script to get data from opened the newly generated excel file, but getting error.

 

Office Script used to get data from excel file

 

function main(workbook: ExcelScript.Workbook,
    wsName: string, startCell: string,
    headerRowsToRemove: number,
    footerRowsToRemove: number) {


    //Declare and assign the worksheet
    let ws = workbook.getWorksheet(wsName);


    //Delare and assign the data range
    let wsRng = ws.getRange(startCell).getSurroundingRegion()


    //Get the values of the data range in array
    let wsRngArr = wsRng.getValues();


    //Count the rows in array
    let wsRngArrRowCount = wsRngArr.length-2;


    //Calcualte the number of rows to return
    let wsRngArrRowLength = wsRngArrRowCount -
        headerRowsToRemove - footerRowsToRemove + 1;


    //Remove the top and bottom rows
    wsRngArr = wsRngArr.slice(headerRowsToRemove, wsRngArrRowLength)
  console.log("Sucessfully Processed.")
    //Return the range
    return { wsRngArr };
  }

 

Flow screen shot for reference.

Getting email attachment to share Point folderGetting email attachment to share Point folder

Run office script
Pic_2.JPG 
 Error message 
Error_Pic_3.JPG 
35 REPLIES 35

I am working with an XLSX file with legacy connections that I cannot remove. I can't use it when creating a table so my script copies the cells in a new worksheet (same .xlsx) then clears all format. Script then deletes any other sheets.

 

The script works on it's own running on the excel file but I want to incorporate it in a Power Automate flow and not do it manually.

It is an xlsx. No, with a blank workbook I am getting the same behavior. The first time I run the flow it works, but then I revert back (re-add the workbook, etc.) and run it again from scratch and it fails each time going forward. 

So it sounds like for both of you, Run Script works with a plain xlsx but your production xlsx files that contain other dependencies do not work. Do you know what this offending dependency is so I can try and repro it on my side? Then we can try and support it in the future.

In my case, a plain XLSX does not work. In both my plain and production XLSX it works the very first time I try to do anything and then fails every time after that. 

In my case the production xlsx is a copy of the plain xlsx from another library. They are the same. So I'm really not sure why it's not working when the script is run in power automate. 

 

jaanihsm_0-1709835217439.png

I also tried creating a new file from production xlsx but I get the same error.

Is it maybe that SharePoint needs to be refreshed after the copy???

kbomysoad
Regular Visitor

After "Create File" add a step called "Find files in folder" using the name of the file that was created in the previous step, then Run Script on the file found in the folder.

Hi! 'Find files in folder' is only for OneDrive files, looks like...

My files are saved in SharePoint. I don't see a function similar to it that will work in SP?

Thanks!

sylwir061
New Member

Hi!

 

Solution proposal! 🙂

 

I just got the same error on a flow that runs for ages without any problems or changes, and two days ago it stopped with the error as in the thread title.

 

The flow uses:

1. SharePoint create file (blank xlsx)

2. RunScript that fills data to the newly created file

 

I tried replacing "create file" with "copy file" - did not help

What did help was this: Solved: Office Script Returning File Format Error - Power Platform Community (microsoft.com)

 

To get the Id I used "Get file metadata using path" (sharepoint) and provided the path manually there. Till now I had that path provided in "Run script", and it worked perfectly well. Now it seems we need an intermediary agent ("Get file metadata using path" for SharePoint/"Find files in folder" for OneDrive), since path will not work anymore when applied to "Run Script" directly.

 

I hope Microsoft will fix this, as it has to be due to some recent changes. Otherwise, if I need to replace file path with "Id" in ALL my flows that use "run script" on newly created files... RIP x_x

I think so far this heeeeelped! Thank you @sylwir061!

 

jaanihsm_0-1710460625417.png

 

Yep, this did the trick!  Replaced this:

Ukiman1014_0-1711745982817.png

With this:

Ukiman1014_1-1711746002463.png

Previous step was SharePoint action to create a copy of the Excel sheet into a different doc library.

netptl39
Frequent Visitor

I have a flow that works and one that fails and I can't figure out why!

Same error: The file format is not recognized. Please check that the selected workbook is valid.

+30sec does nothing. 

Automation Script works when I run it from the opened excel.

Any sugestions on why would be highly welcomed! 

I have the same issue. My script works fine in excel but not via power automate. 
clientRequestId: c871bd5d-7eeb-4afa-8372-2ab6e85bb7f1

markbowler7
New Member

I am suddenly getting this issue today. Scripts were working fine yesterday - running on .xlsx files in SharePoint. I've dropped in new versions of the files today via a OneDrive shortcut to the folder from my Downloads folder using File Explorer. Files open in Excel desktop and online with no issues - why is this so flaky?

Ah, found out what this issue was - dragging and dropping the files (even though the name was the same) into the linked folder using File Explorer caused them to be treated as new items in SharePoint (previous history all wiped out), hence the script couldn't find them (as I think the scripts use the SharePoint ID rather than the file/path name). Pity the error message was so confusing - if it had said file not found it might have been more obvious!

This is good feedback, I'll give the team feedback on this error message.

PhilatVeriset
Frequent Visitor

We ran into the same error after using ennvironment variables for a dynamic input when the automation is transferred to another ennvironment aka from dev to test, from test to prod.

Our files are xlsm format and we still made it work.

 

We found out that the Workbook Library must be entered in a speical code format, which is not very intuitive:

PhilatVeriset_1-1716899622166.png

 

You can find this b!uhPM...-value when loooking it up from a past execution which has been successful or sometimes it is visible when the connection to the file is broken/lost. Otherwise I am note sure how to generate or find it.

 

Hope this helps!

 

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,342)