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
GeoffRen
Employee
Employee

- Are you sure the Folder Path from Create file 3 and Document Library from Get data from a file exactly the same?

- Can you open the newly created file in Excel normally?

- Do any of the other Excel actions work instead of Run Script?

- Are you able to select the newly created file in an Excel action in a different Flow?

kfulton
Advocate I
Advocate I

I am having this same issue -- following.

I am able to open the workbook in question on my computer and it is a typical .xlsx format.

Darkventure
Regular Visitor

I accidentally figured this out last week and forgot to circle back. My issue was that my script creates new sheets for each new dataset. The sheet name was to long sometimes (31 character limit) and would just fail. 

I landed here because I am getting the same error & it also involves a script that renames a sheet, but the sheet name is fixed & very short, so there's gotta be something else in play there. As it happens, I think I can just eliminate the sheet rename from my flow altogether.

jaanihsm
Helper III
Helper III

I am experiencing the same. Sheet new name is very short...anyone who is able to help? I have also tried to Get file content (from another library)> Create file > Delay > Run script from SP library but I get the same error. The file is saved successfully but it cannot read it? Hoping someone can help! Thanks!

 

jaanihsm_0-1709600629920.png

 

Hi! Did the removal of sheet renaming resolved the issue for you? Thanks!

Well, yes, but that was the only thing my Office Script was doing, so I just eliminated that Office Script step altogether. Is the file that is throwing the error created as an earlier step in your flow?

Yes it is a file created from an earlier step. This file is a duplication of the original file from another library (Get file content > Create file). I also tried 'Copy file' but get the same error. And even if I just dump the file, same error. I don't know what's wrong. 

By the way, my script is doing a copy sheet to a new sheet to drop all legacy connections then rename sheet. This way the excel table for the data gets successfully created.  

I have found that Power Automate/Excel connectors don't always like to play nice with freshly created files; it seems that Power Automate goes to look at that file to see how the Excel file is structured & can't straightforwardly do so with dynamic file paths. This video explains how to 'trick' it into recognizing the base code of the dynamic file for updating rows. Hopefully, you can extrapolate from this to solve your particular flow. 

https://youtu.be/caPFTd8CCdk?si=KA0J0ENFdavhZN4a

Can you post your entire script?

Hi! This is the Office Script:

 

function main(workbook: ExcelScript.Workbook) {
    let selectedSheet = workbook.getActiveWorksheet();
    // Delete first worksheet
    let in_Progress_Report = workbook.getWorksheet("In Progress Report");
    // Unfreeze panes on selectedSheet
    selectedSheet.getFreezePanes().freezeAt(null);
    // Delete range 1:2 on selectedSheet
    selectedSheet.getRange("1:2").delete(ExcelScript.DeleteShiftDirection.up);
    // Add a new worksheet with name "DataToSP"
    let dataToSP = workbook.addWorksheet("DataToSP");
    // Paste to all cells on dataToSP from all cells on selectedSheet
    dataToSP.getRange().copyFrom(selectedSheet.getRange(), ExcelScript.RangeCopyType.all, false, false);// Delete first worksheet
    //Delete second worksheet
    let last_Issued_Revision = workbook.getWorksheet("Last Issued Revision");
}

This is strange, I can see that it works in Excel but not in Power Automate. Do you have a clientRequestId from an unsuccessful run?

mickey97
Regular Visitor

I am getting the same error. The only thing my script is doing is delete one tab. About 25% of the time it runs successfully, but the other 75% of the time if fails for that reason. It is the same workbook - nothing is changing in the workbook or the flow. Any insight as to why the Run Script action continuously fails would be greatly appreciated.

Can you post your script and a clientRequestId for a failing Flow action?

Hi! My office script is:

 

function main(workbook: ExcelScript.Workbook) {
    let selectedSheet = workbook.getActiveWorksheet();
    // Delete first worksheet
    let in_Progress_Report = workbook.getWorksheet("In Progress Report");
    // Unfreeze panes on selectedSheet
    selectedSheet.getFreezePanes().freezeAt(null);
    // Delete range 1:2 on selectedSheet
    selectedSheet.getRange("1:2").delete(ExcelScript.DeleteShiftDirection.up);
    // Add a new worksheet with name "DataToSP"
    let dataToSP = workbook.addWorksheet("DataToSP");
    // Paste to all cells on dataToSP from all cells on selectedSheet
    dataToSP.getRange().copyFrom(selectedSheet.getRange(), ExcelScript.RangeCopyType.all, falsefalse);// Delete first worksheet
    //Delete second worksheet
    let last_Issued_Revision = workbook.getWorksheet("Last Issued Revision");
}
 
I just ran it here is the clientRequestID:
 
The file format is not recognized. Please check that the selected workbook is valid.
clientRequestId: af36585c-5577-49bc-9099-d422c020e0fc

Here is the recent clientRequestID:

 

The file format is not recognized. Please check that the selected workbook is valid.
clientRequestId: af36585c-5577-49bc-9099-d422c020e0fc

function main(workbook: ExcelScript.Workbook) {
    let instructions = workbook.getWorksheet("Instructions");
    // Set sheet visibility to hidden
    instructions.setVisibility(ExcelScript.SheetVisibility.hidden);
}
 
This is the full flow that I built. It includes the script action in addition to other actions. However, it continuously fails on the script action. 467eea7e-f846-417b-9f2e-491410ff7062
This is a flow I created to test the script action. All this flow does is run the script:6bff9a27-df8c-4071-9493-4a032ccd70c0

I don't see any additional information other than the error posted for either of you. What file extension is the workbook you're using? Does the Flow work if you run it on a plain .xlsx file?

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 (4,547)