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

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

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

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (933)