Imagine that you day week has to get data from some databases, add this in an Excel file that is then e-mailed to someone. How could you automate this in Logic Apps? Also, is it worth it? Maybe.

Strategy

In short, the logic app will go thru these steps:

  • Create an empty Excel file. Believe it or not, this is was the hardest problem for me to solve.
  • Prepare the Excel-file by creating a new sheet and a new table.
  • Populate the table with some data.
  • Send the file via e-mail.

In real life, there are some more steps involved. If you follow this tutorial you will end up with these steps:

Logic app overview

Start by creating an empty Logic app. Normally I use the When a HTTP request is received trigger when I do experiment like this, but feel free to use whatever you like.

Create an empty Excel file

There are ready to use connectors for working with Excel files. All these assumes that the files exist on OneDrive, so we will use that. The files will just be temporary.

But unfortunately, the are no functions that let us use easily create an empty Excel file. Not sure why, I find this to be a bit weird to be honest.

One way to solve this is to have a template file ready and then use the OneDrive connector to copy to new file. Easy to do and totally works. But I find it a bit annoying that need a file on my OneDrive just for that. If I accidentally remove that file, the app will stop working.

But the approach we will use is to have the content inside the app and then write it to a real file. Since Excel files are binary files, we will work with the file content as a base64 string. If you have a file ready that you want to use, you could run this PowerShell command to get the content in the right format:

PowerShell
[Convert]::ToBase64String([IO.File]::ReadAllBytes(".\MyFile.xlsx"))

Otherwise, just use the sample I have below.

In your Logic app, select to add a new step.

Search for Variables.

Select Variables

Then select Initialize variable.

Select Initialize Variable

Let Name be EmptyFileContent, and the Type should be an Object. The Value should be this massive string:

EmptyFileContent
{
  "$content": "UEsDBBQAAAgIAPw7F1H5Vy4RAgEAALoBAAAPAAAAeGwvd29ya2Jvb2sueG1sjZDBbgIhEIZfhcy9sm5i22xEL714aZrUtGeEwSUusGFQ99166CP1FQq7Gk1PPfHPDN8/P/x8fS/Xg+vYCSPZ4AXMZxUw9Cpo6/cCjsk8PMN6tRyac4iHXQgHlu97aqKANqW+4ZxUi07SLPTo88yE6GTKZdzzYIxV+BLU0aFPvK6qRx6xkynvotb2BBe34T9u1EeUmlrE5LrJzEnr4T7dW2Q5O75KhwK2raXPywAYL/eK/LB4pnuoNJixkdJ7MReQ/0CqZE+4lbu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MS54bWxQSwECFAAUAAAICAD8OxdRdbGRXrcFAAC7GwAAEwAAAAAAAAAAAAAAAACmCwAAeGwvdGhlbWUvdGhlbWUxLnhtbFBLAQIUABQAAAgAAP07F1FcDRM/2gEAANoBAABRAAAAAAAAAAAAAAAAAI4RAABwYWNrYWdlL3NlcnZpY2VzL21ldGFkYXRhL2NvcmUtcHJvcGVydGllcy9mYjZlNjQxMDQ4N2I0NzcxYWQxNzQxMDgwMTM4YWEyZi5wc21kY3BQSwECFAAUAAAICAD9OxdREZTACDkBAAA3BAAAEwAAAAAAAAAAAAAAAADXEwAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLBQYAAAAACgAKAMACAABBFQAAAAA=",
  "$content-type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}

Initialize Variable configuration

Now add a new step. I will use OneDrive for Business, but I think ordinary OneDrive will work too.

OneDrive for Business

Select the Create file action.

Create file

Pick any folder you think is appropriate. I will use a temp folder.

The file name could be whatever you like. I prefer to use a file name that will be unique, so I have added the date with the expression:

Date expression
substring(utcNow(), 0, 10)

And the time with the expression:

Time expression
replace(substring(utcNow(), 11, 8), ':', '')

The file content should be the variable the created in the previous step. If you cannot see the variable in the dynamic content list, just use this expression instead:

File content expression
variables('EmptyFileContent')

The configuration should look like this:

Create file configuration

Prepare the Excel file

Now when we have an Excel file to play with, we could start to modify it.

We start by creating a new worksheet. Add a new step and select Excel Online (Business).

Excel Online (Business)

Select the action Create worksheet.

Create worksheet

The Location should be OneDrive for Business, and the Document Library should have the value OneDrive.

The file parameter should be the file we previously created. Add this as a dynamic expression. Select the File locator value.

Lastly, let the Name be Players.

Create worksheet configuration

Now we will create a table on the worksheet we just created. Add a new step again. Select OneDrive for Business, and select the action Create table.

Create table

Setup up Location, Document Library and File just like you did in the previous step.

In the Table range parameter enter:

Table range expression
Players!A1:C1

Also add the Table name and Column names parameters.

Let Table name have the value TablePlayers.

Let Columns names have the value:

Column names
PlayerID; First name; Last name

The configuration should look like this:

Create table configuration

Adding some data

Now it is time to add some data. Normally you will get the data from a SQL database or something similar. There are connectors for this that is easy to use. But to keep this tutorial simple we will hard code some values instead.

Add a new step and search for Data Operations.

Data operations

Select the action Parse JSON.

Parse JSON

Add this as Content:

JSON Data
{
  "Players": [
    {
      "PlayerID": 1,
      "FirstName": "Alice",
      "LastName": "Aliceson"
    },
    {
      "PlayerID": 2,
      "FirstName": "Bob",
      "LastName": "Bobsson"
    },
    {
      "PlayerID": 3,
      "FirstName": "Carol",
      "LastName": "Carlsson"
    },
    {
      "PlayerID": 4,
      "FirstName": "David",
      "LastName": "Davidsson"
    },
    {
      "PlayerID": 5,
      "FirstName": "Eric",
      "LastName": "Ericsson"
    },
    {
      "PlayerID": 6,
      "FirstName": "Frank",
      "LastName": "Franksson"
    }
  ]
}

Also click on Use sample payload to generate schema and paste the data and press OK.

Parse JSON configuration

Now we will iterate thru all this data. Add a new step and select the Control connector.

Control

Select the For each action.

For each

In Select an output from previous step select Players from Dynamic content.

For each configuration

Now select add an action inside the For each controller. Select Excel Online (Business) and then select the action Add a row into a table.

Add a row into a table

Setup up Location, Document Library and File just like you did in the previous step.

In Table enter TablePlayers.

The Body parameter should be an JSON object. Configure it like this:

Add row configuration

You find the variables in the Dynamic content.

In the documentation of the Excel Online (Business) connector you find that there is a limit of 100 calls per minute. If you do more than this your app will stop working. So, in the For each loop it might be a good idea to add a short delay after each row has been written. With the sample data we are using this is not an issue so we will skip that.

Also, when all the rows have been written it might be a good idea to add a delay for a minute or so. I have noticed that sometimes some data has been missing in the e-mail that we soon will be send.

Sending file as an E-mail attachment

Now when the file is created, we will send the file via e-mail. Before we do that, we need to read the file content.

Add a new step and select the connector OneDrive for Business.

OneDrive for Business

Select the action Get file content.

Get file content

Let the File parameter be the File locator variable that you have use many times before.

Get file content configuration

Now, add a step. This time use the connector Office 365 Outlook.

Office 365 Outlook

Use the action Send an email.

Send an e-mail

The parameters To, Subject and Body is obvious so enter whatever you like in the.

Then add Attachments parameter.

In the Attachments Name enter playerreport.xlsx.

In the Attachments Content use the value from the previous Get file content step. You might need to click on See more.

Send an email configuration

That is all! You Logic app is now completed. Run the app to see if it works.

Summary

I think this was a fun little experiment and it works OK once all pieces are in place. I struggled a long time on how to create the Excel file, but once that was solve things were pretty much straightforward.

All this said, there are a couple of downsides with this solution:

  • The temporary file that is created is never removed. I did this intentionally to keep the app as simple as possible. It is easy to add a new step that remove the file via the OneDrive for Business connector. Note that you may need to add a delay for several minutes before you remove the file.
  • The first worksheet in the Excel file is empty. Unfortunately, there is no support to delete existing sheets when I write this. You could workaround this by using another template and not adding a worksheet in the logic app.
  • All columns in the table is just 64 pixels wide or so. I have not an elegant solution for this. Again, you could workaround this with a different template were all tables and sheets are premade.
  • Writing rows is due the limit of 100 actions per minute a bit slow. So large reports could take a couple of hours to generate. Might not be a problem be is something to be aware of.

I am not totally satisfied with the solution. Generating Excel is nothing new to me, there are some good NuGet packages out there that make this pretty easy. If you do this you have better control of everything, and it will be way faster. But I could see where a solution with a logic app would be good enough, so it is good have this this in the toolbox.