Flow: Excel Formats Only | Save New Email Attachments to SharePoint
If you want to save just "Excel files" or just "Word Files" to a SharePoint Library, then multiple file formats must be considered. Excel has several formats and so does Word although below are the most common types that you are likely to receive by email.
MS Excel = .xlsx, .xls, .csv (and others)
MS Word = .docx, .doc (and others)
When using "Dynamic content", a common way to get the file name is to use "Attachments name" from the "Get email" action. This is great and very simple, but what if you already have files of the same name in that location?
The answer, it will overwrite the old file. This may be what you want and if so great, but what if a system generates a file called "report.csv" every day and sends it to you. You may want to keep a hold of all the reports.csv version that arrive daily.
Wouldn't it be better to save reports.csv as reports-2019-03-08-19-15-20.csv so that each new version doesn't conflict with the last?
This is ultimately what we will achieve in this how-to Flow blog post.
Would you like to buy Alan a coffee?
Visit the AlanPs1 Ko-fi page
The method I will now step through triggers on receipt of a new email, captures the file format then adds a time stamp to the end of the file name on save.
Here is the completed Flow.
In this example I will address Excel file types. This could be altered to accommodate Word file types or any other but the basic principals remain the same.
Here is the trigger.
Then we "Get email"
We capture the "Current Time".
Then initialise our first variable.
Our second variable, we will set it later.
There may be multiple attachments. They may all be excel, some may be images such as .jpg or .png so we move on to setting an "Apply to each". I have named it "Apply to each Attachment on the email"
Within it, we will use a "Condition". It is named "Condition 2" in this example but can be named whatever you like.
There is no use for the "No" branch of the condition in this Flow so we will now cover the "Yes" branch.
Below uses a split to allow us to isolate the file type or extension as well as the file name. It breaks into 2 minus the dot. This will work perfectly, assuming there are no dots in the file name itself.
Note: This could be further enhanced to mitigate against dots in file names but I would really hope the file names you are receiving do not contain dots, it's frowned upon, certainly by me.
Note: Enhancement to remove dots or special characters posted here. Strip Dots and Special Characters from File Names.
The  targets the 2nd part of the array. This will be the file extension minus the dot. I.e. csv, xlsx, xls.
Let's bring it all together and create the file in your SharePoint library.
Notice the first part of the array, denoted by  we will call File Name, "TimeStamp" and "FileExtension" are separated with either "-" or "." in order to create a file like the following:
Note: Another variable could be used to store outputs('Compose_FileExtension') although I have left that out to demonstrate different ways of targeting the data after the split.
Visit the Get Help section of the Power Automate Community