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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Copy Excel Template on...
Power Automate
Suggested Answer

Copy Excel Template on SharePoint List Change and Update Table

(2) ShareShare
ReportReport
Posted on by 37
Hello there,
 

My initial situation

I have a SharePoint list with many columns and a lot of entered information. This list serves as a kind of database for pre‑series and zero‑series projects and is also intended to act as a workflow trigger at different points in time.

Current goal

Whenever a SharePoint list item is created or modified, an Excel template should be copied in the background and saved as a new file using the list item ID as the file name.

The Excel file contains a table that should be populated with data from the corresponding SharePoint list item.

Afterwards, the Excel file should be attached to the SharePoint list item as an attachment and updated every time certain columns in the SharePoint list change.

What I have tried so far

I already experimented with several approaches but haven’t reached the desired result yet.

My first approach was to copy the Excel template using “Get file contents using path” and then save it under the list item ID.

However, when I try to add a row to the Excel table, it fails because the table cannot be found — apparently because it does not yet exist (or is not recognized at that point).

Additionally, I would need to implement a logic that clears existing rows in the Excel table before writing new data, so that the file is always up to date.

Current problem

Right now, I’m missing the right conceptual approach on how to proceed from here:

  • How to correctly copy the Excel template and reliably access the table afterwards
  • How to handle updating the Excel file when the SharePoint item changes (and the file already existists)
  • How to clear and rewrite table data in a clean way

Any guidance or best practices would be highly appreciated.

Categories:
I have the same question (0)
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @TechnikiDIY,
     
    You can follow these steps as guide: 
     
    1. Trigger: When an item is created or modified: Let’s use SP trigger "When an item is created or modified". Configure it to point to your SharePoint list.
    2. Initialize variables (optional but recommended): Initialize variables to store the SP item ID and other relevant data for easier reference.
    3. Copy the Excel template file: We can use "Get file content using path" action to get the Excel template file from SharePoint or OneDrive. Next, let’s use the "Create file" action to create a new Excel file in a target folder (e.g., a project documents folder), naming it with the SharePoint item ID
    4.  (e.g., @{triggerOutputs()?['body/ID']}.xlsx).
    5.  
    6. Add a delay or check to ensure the file is fully created: For better benefit let’s  Add a Delay action (e.g., 10-15 seconds) or implement a loop with a "Get file metadata" action to confirm the new file is accessible.
    7. List rows present in the Excel table: Use the "List rows present in a table" action from the Excel Online (Business) connector. Point it to the newly created Excel file and specify the table name.
    8. Clear existing rows in the Excel table: Use an "Apply to each" loop on the rows returned. Inside the loop, use the "Delete a row" action to remove each existing row.
    9. Add a new row with SharePoint item data: Use the "Add a row into a table" action. Map the SharePoint list item fields to the corresponding Excel table columns.
    10. Attach the updated Excel file back to the SharePoint list item: Use the "Get file content" action to read the updated Excel file. Use the "Add attachment" action to attach the Excel file to the SharePoint list item.
    11. Handle errors gracefully – with best practices.
     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
  • Suggested answer
    rezarizvii Profile Picture
    352 on at
    Hi @TechnikiDIY, hope you are doing well.
     
    Here is a blueprint of how you can setup your flow:
     
    1. When an item is created or modified: Set your Site Address and List Name in the trigger.
     
    2. Get file content using path: Get the content of the template file by specifying where the template lives i.e., Site Address and File Path.
     
    3. Create file: Here, simply create a new file based on the content of the template. If a file with the same name exists in that location, SharePoint will automatically replace the file. Essentially, you will have the same file with the same name and metadata but with its entire content replaced with the template content.
    File Name: @{triggerBody()?['ID']}.xlsx
    File Content: @{body('Get_file_content_using_path_[Template]')}
     
    4. Add a row into a table: Here you can select the file that you just created/replaced and enter the values from your list item as a row.
    File: @{outputs('Create_file')?['body/Path']}
    Table: This has to be hardcoded to what the table is called in the template.
    Row: Here, you need to provide an object of what you want to insert in the table formatted as the screenshot above.
     
    From here on, you can go ahead and attach is as an attachment back to the list item.
     
     
    Note: SharePoint locks files once they have been opened by a user or updated. You may get a "The file <file-path> is locked for shared use by <user-email>." error. This is a known issue with SharePoint. To resolve it, you can refer to the following workaround: Power Automate – Avoiding “File Locked For Shared Use” Failing Your Workflow - Thrive
     
     
    ===============================================================
    If this reply helped you in any way, please mark 'Yes' for "Was this reply helpful?" and give it a Like 💜
    In case it resolved your issue, please mark it as the Verified Answer ✅. 
  • TechnikiDIY Profile Picture
    37 on at
    Thank you for the guidance.
     
    For the Action "Create file" the flow runs into the error "Action 'Create_file' failed: A file with the name XXXXXXX/320.xlsx already exists."
     
    The Action "Copy File" has an option for overwriting existing files with the same name, but the "create file" action does not have this option.
    Do I need to insert a "Condition" and different paths for when the file already exists and I want to update that file?
     
  • Suggested answer
    rezarizvii Profile Picture
    352 on at
     
    The "Copy File" action would not work here as it does not let you rename the file that you just copied and SharePoint does not expose a direct "Rename File" action.
     
    Perhaps you do have to add a condition, but not the usual kind. You have to check if a file exists in the location or not, but there are no actions that only check for a file and return true or false. You have to add another "Get file content using path" action. But here, if the file does not exist, the action would just fail.
     
    I suggest you wrap that conditional "Get file content using path" in a Scope block. A Scope block is like a try/catch block in Power Automate. You can wrap the conditional "Get file content using path" in it and then configure different scenarios for when it fails and when it succeeds.
     
    Here is how your updated flow should look like:
     
    The first two actions (trigger and the subsequent action) would essentially be the same.
     
    3. Scope: Add a scope block and inside it, add another Get file content using path action. Set the Site Address and for the path, enter the entire path along with the file name i.e., if the file exists in Documents as 123.xlsx, enter: /Documents/@{triggerBody()?['ID']}.xlsx (see the update file screenshot below for an example)
     
    4A. Create file: The action would essentially be the same, just need to update the "Run after" setting. Click on the action, navigate to the Settings tab, and under "Run after" expand the Scope, select "Has failed" and deselect everything else. What this essentially does is configure the action to only run when the Scope block has failed i.e., when an existing file DOES NOT exist.
     
    4B. Update file: Click on the + icon right after the scope and add a parallel branch and add an Update file action. This action will update the existing file with the content of the template, basically clearing all the data to allow new data to be entered. Configure the "Run after" setting for this action by only selecting "Is successful" and deselecting everything else. This tells the flow to run this branch only when the Scope block succeeds i.e., an existing file DOES IN FACT exist.
    Site Address and File Identifier: Same as the Get file content using path.
    File Content: File content of the template i.e., @{body('Get_file_content_using_path_[Template]')}
     
    You can then add the same Add a row into a table action from the other branch and configure similarlly. Keep in mind, actions in separate branches cannot reference each other. An action can only reference another action in the same branch or the actions that were common before the branch split.
     
    This will create a sort of condition in your flow where it will first check if the file exists, and based on that, it will decide to either create a new file or update the existing file by deleting all the data and entering the data anew.
     
     
    =====================================================
    And I'll say this again, if this reply helped you in any way, please mark 'Yes' for "Was this reply helpful?" and give it a Like 💜 and in case it resolved your issue, please mark it as the Verified Answer ✅. It would be highly appreciated.
  • rezarizvii Profile Picture
    352 on at
    Hi @TechnikiDIY, hope you are doing well.
     
    Just wanted to check in and see if everything is working now. If you still need any help, feel free to let me know.
    Also, if the issue is resolved, it would be great if you could mark the answer as solved so others with the same question can find it easily.
     
    Thanks and have a great day!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard