Excel File Tricks with PowerAutomate

Published Aug 04 2021 11:06 AM 1,801 Views
Senior Member

A little secret....

First of all, if you don't know already and you want to quickly create an excel or word file on your OneDrive, try http://excel.new or http://word.new

 

In the following post I will cover three ideas:

1. Splitting a workbook with many worksheets into unique workbooks containing one sheet

2. Creating a new excel file and populating it with data

3. Converting a CSV into an Excel File

 

Splitting a Workbook

This solution requires a bit of Office Script typescript in order to identify the number of worksheets in a workbook and delete the sheets that are no longer required.  I've written two basic scripts to do the following:

 

1. "GetSheetNames": retrieve a list of sheets and returns an array to PowerAutomate and;

 

 

function main(workbook: ExcelScript.Workbook) {
	// Get all the worksheets in the workbook. 
	let sheets = workbook.getWorksheets();

	// Get a list of all the worksheet names.
	let names = sheets.map((sheet) => sheet.getName());

	return (names)
}

 

 

2. "DeleteSheets": delete the sheets from a workbook based on an array input, returning the number of sheets in the workbook (hopefully 1!)

 

 

function main(workbook: ExcelScript.Workbook,
  SheetsToDelete: Array<string> = [],
)
{

//for each of the worksheets in the array
  for (let worksheet of SheetsToDelete) {
    //delete the worksheet
    workbook.getWorksheet(worksheet).delete();
  }

//get current worksheets in workbook
  let sheets = workbook.getWorksheets();
  let names = sheets.map((sheet) => sheet.getName());
  
  //return the number of sheets left
  return(names.length)

}

 

 

This allows us to create a flow that will:

1. return an array of sheet names in our first office script action

2. create a copy of the original excel file with the sheet name prefixed to the file name

3. delete all but the unique sheet for each copy

 

This is what the flow looks like:

 

When a file is created in our folder location (in this case OneDrive but equally it would work on SharePoint), we get the worksheet names and then get the file content of the original file.

 

DamoBird365_0-1628093847880.png

 

Then in an apply to each, we use the results array from the "GetSheetNames" office script, and iterate through each item using a filter array to return an array of all but the current sheet name (i.e. where item() is not equal to items('Apply_to_each') or "Current Item").  If we have an array of five sheets, the filter will return four sheets.  Then we can create a copy of the original file using the file content and a prefix of "Current Item".  Finally calling the "Delete Sheets" Office Script using the dynamic Id of the Create File Action, based on the result of the filter array.  

 

DamoBird365_1-1628094142942.png

The end result is an excel workbook, containing one sheet and as we are in an apply to each, we end up with five worksheets, each with a unique worksheet.  Below we have the original workbook containing five worksheets.

 

DamoBird365_3-1628094699559.png

 

Here we see the individual workbooks on OneDrive, prefixed with the sheet name:

 

DamoBird365_2-1628094676818.png

Now we have a single workbook with a unique sheet, called "ATable":

 

DamoBird365_4-1628094930996.png

 

Why might you want to do this?  If you maintain a single workbook with multiple sheets and want to share a copy of each worksheet with individuals or teams, this would allow you to achieve that without compromising the original file.  You could routinely split up your workbook and send a copy of each worksheet to your colleagues via email or Teams.

 

Watch the full build and demonstration here:

 

 

Create an empty Excel File

Natively, PowerAutomate doesn't allow you to create a new Excel file.  By creating an empty Excel file on SharePoint and using the get file content action, it's possible to save the JSON output to a compose and re-use the empty template file when using the "create file" action.

 

DamoBird365_0-1628095727802.png

A compose action with the File Content copied into it.  

 

DamoBird365_1-1628095823450.png

By doing it this way, we achieve two things.

1. no need for the donor empty excel file, we can delete it and not have to worry about it being deleted accidentally

2. we can remove the get file content action and rely entirely on the compose action we have created

 

By using the output of the compose action we can create a new file (in this case named with a unique datetime string formatdatetime(utcnow(),'yyyyMMddhhmmss').xlsx and then create a new table to allow data to be inserted.  Here we have a table range from column A to E on row 1, i.e. 5 columns with headers Name, Age, Address1, Address2, PostCode.

 

DamoBird365_2-1628096048590.png

To populate our excel file, I have an array contained within a compose, this data array could be the result of another action or a filter or OData query on another Excel Worksheet that you simply want to save a copy of:

 

DamoBird365_4-1628096378139.png

 

 

Then using an apply to each and the compose array as an input we can add rows to the table and construct the row input array for our "add a row" action with keys / name pairs based on the column headers from the create table action. 

 

 

 

 

{
  "Name": "@{items('Apply_to_each')?['Name']}",
  "Age": "@{items('Apply_to_each')?['Age']}",
  "Address1": "@{items('Apply_to_each')?['Address1']}",
  "Address2": "@{items('Apply_to_each')?['Address2']}",
  "Postcode": "@{items('Apply_to_each')?['Postcode']}"
}

 

 

 

 

The table name is provided dynamically from the create table action and the File Id is the dynamic value from the create file action.

 

DamoBird365_3-1628096174072.png

If we turn on concurrency, we can add 50 rows to the newly created excel file in a matter of seconds.  Whilst I haven't covered this here, it would be possible to write an office script to take an array of objects and populate an excel file without a table.  I have previously covered this concept here Excel Scripts and Cloud Flows - Data Manipulation - Microsoft Tech Community.  

 

Watch how you can create a new file via PowerAutomate here:

 

 

And Finally, converting a CSV to Excel File

All we are doing is swapping out the array contained within the compose action and converting a CSV to an Array.

 

Here we have a CSV contained within a compose and another compose action with a return line (literally press return on your keyboard).  Then using split, we turn the CSV into an array of separate lines.

 

DamoBird365_5-1628096964541.png

 

Using the select action, the from array input is the output from the compose splitline array (skipping object one, which contains the header line) and in this case I have supplied the key names manually.  Finally the expression used to obtain the value is a split of each item (Or line) based on the separator, the comma ','. 

 

This will allow us to call each value by integer index split(item(),',')[0].

 

DamoBird365_6-1628097127838.png

Our select action take an array of comma separated lines and outputs an array of key/value pairs like follows:

DamoBird365_7-1628097240857.png

 

And if we update the apply to each source as the select output, we end up with a new excel file using a CSV file as our input:

DamoBird365_8-1628097338222.png

 

For more information about parsing CSV files in PowerAutomate, please read my blog article How To Parse any CSV to JSON Array - DamoBird365.

 

More ideas and concepts on my YouTube or Blog.  Please feel free to reach out if you have any questions.

%3CLINGO-SUB%20id%3D%22lingo-sub-2611337%22%20slang%3D%22en-US%22%3EExcel%20File%20Tricks%20with%20PowerAutomate%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2611337%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--384856778%22%20id%3D%22toc-hId--384856778%22%3EA%20little%20secret....%3C%2FH2%3E%0A%3CP%3EFirst%20of%20all%2C%20if%20you%20don't%20know%20already%20and%20you%20want%20to%20quickly%20create%20an%20excel%20or%20word%20file%20on%20your%20OneDrive%2C%20try%20%3CA%20href%3D%22http%3A%2F%2Fexcel.new%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fexcel.new%3C%2FA%3E%26nbsp%3Bor%20%3CA%20href%3D%22http%3A%2F%2Fword.new%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttp%3A%2F%2Fword.new%3C%2FA%3E.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20following%20post%20I%20will%20cover%20three%20ideas%3A%3C%2FP%3E%0A%3CP%3E1.%20Splitting%20a%20workbook%20with%20many%20worksheets%20into%20unique%20workbooks%20containing%20one%20sheet%3C%2FP%3E%0A%3CP%3E2.%20Creating%20a%20new%20excel%20file%20and%20populating%20it%20with%20data%3C%2FP%3E%0A%3CP%3E3.%20Converting%20a%20CSV%20into%20an%20Excel%20File%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2102656055%22%20id%3D%22toc-hId-2102656055%22%3ESplitting%20a%20Workbook%3C%2FH2%3E%0A%3CP%3EThis%20solution%20requires%20a%20bit%20of%20Office%20Script%20typescript%20in%20order%20to%20identify%20the%20number%20of%20worksheets%20in%20a%20workbook%20and%20delete%20the%20sheets%20that%20are%20no%20longer%20required.%26nbsp%3B%20I've%20written%20two%20basic%20scripts%20to%20do%20the%20following%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20%22GetSheetNames%22%3A%20retrieve%20a%20list%20of%20sheets%20and%20returns%20an%20array%20to%20PowerAutomate%20and%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Efunction%20main(workbook%3A%20ExcelScript.Workbook)%20%7B%0A%20%2F%2F%20Get%20all%20the%20worksheets%20in%20the%20workbook.%20%0A%20let%20sheets%20%3D%20workbook.getWorksheets()%3B%0A%0A%20%2F%2F%20Get%20a%20list%20of%20all%20the%20worksheet%20names.%0A%20let%20names%20%3D%20sheets.map((sheet)%20%3D%26gt%3B%20sheet.getName())%3B%0A%0A%20return%20(names)%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20%22DeleteSheets%22%3A%20delete%20the%20sheets%20from%20a%20workbook%20based%20on%20an%20array%20input%2C%20returning%20the%20number%20of%20sheets%20in%20the%20workbook%20(hopefully%201!)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-javascript%22%3E%3CCODE%3Efunction%20main(workbook%3A%20ExcelScript.Workbook%2C%0A%20%20SheetsToDelete%3A%20Array%3CSTRING%3E%20%3D%20%5B%5D%2C%0A)%0A%7B%0A%0A%2F%2Ffor%20each%20of%20the%20worksheets%20in%20the%20array%0A%20%20for%20(let%20worksheet%20of%20SheetsToDelete)%20%7B%0A%20%20%20%20%2F%2Fdelete%20the%20worksheet%0A%20%20%20%20workbook.getWorksheet(worksheet).delete()%3B%0A%20%20%7D%0A%0A%2F%2Fget%20current%20worksheets%20in%20workbook%0A%20%20let%20sheets%20%3D%20workbook.getWorksheets()%3B%0A%20%20let%20names%20%3D%20sheets.map((sheet)%20%3D%26gt%3B%20sheet.getName())%3B%0A%20%20%0A%20%20%2F%2Freturn%20the%20number%20of%20sheets%20left%0A%20%20return(names.length)%0A%0A%7D%3C%2FSTRING%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20allows%20us%20to%20create%20a%20flow%20that%20will%3A%3C%2FP%3E%0A%3CP%3E1.%20return%20an%20array%20of%20sheet%20names%20in%20our%20first%20office%20script%20action%3C%2FP%3E%0A%3CP%3E2.%20create%20a%20copy%20of%20the%20original%20excel%20file%20with%20the%20sheet%20name%20prefixed%20to%20the%20file%20name%3C%2FP%3E%0A%3CP%3E3.%20delete%20all%20but%20the%20unique%20sheet%20for%20each%20copy%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20what%20the%20flow%20looks%20like%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20a%20file%20is%20created%20in%20our%20folder%20location%20(in%20this%20case%20OneDrive%20but%20equally%20it%20would%20work%20on%20SharePoint)%2C%20we%20get%20the%20worksheet%20names%20and%20then%20get%20the%20file%20content%20of%20the%20original%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_0-1628093847880.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300547i18FE68F8DFC2C168%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1628093847880.png%22%20alt%3D%22DamoBird365_0-1628093847880.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20in%20an%20apply%20to%20each%2C%20we%20use%20the%20results%20array%20from%20the%20%22GetSheetNames%22%20office%20script%2C%20and%20iterate%20through%20each%20item%20using%20a%20filter%20array%20to%20return%20an%20array%20of%20all%20but%20the%20current%20sheet%20name%20(i.e.%20where%20item()%20is%20not%20equal%20to%20items('Apply_to_each')%20or%20%22Current%20Item%22).%26nbsp%3B%20If%20we%20have%20an%20array%20of%20five%20sheets%2C%20the%20filter%20will%20return%20four%20sheets.%26nbsp%3B%20Then%20we%20can%20create%20a%20copy%20of%20the%20original%20file%20using%20the%20file%20content%20and%20a%20prefix%20of%20%22Current%20Item%22.%26nbsp%3B%20Finally%20calling%20the%20%22Delete%20Sheets%22%20Office%20Script%20using%20the%20dynamic%20Id%20of%20the%20Create%20File%20Action%2C%20based%20on%20the%20result%20of%20the%20filter%20array.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_1-1628094142942.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300548i14E0D62ECBD5DE63%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_1-1628094142942.png%22%20alt%3D%22DamoBird365_1-1628094142942.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20end%20result%20is%20an%20excel%20workbook%2C%20containing%20one%20sheet%20and%20as%20we%20are%20in%20an%20apply%20to%20each%2C%20we%20end%20up%20with%20five%20worksheets%2C%20each%20with%20a%20unique%20worksheet.%26nbsp%3B%20Below%20we%20have%20the%20original%20workbook%20containing%20five%20worksheets.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_3-1628094699559.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300552iDBF77C886AD799E2%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_3-1628094699559.png%22%20alt%3D%22DamoBird365_3-1628094699559.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20we%20see%20the%20individual%20workbooks%20on%20OneDrive%2C%20prefixed%20with%20the%20sheet%20name%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_2-1628094676818.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300551i304909991C344C6F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_2-1628094676818.png%22%20alt%3D%22DamoBird365_2-1628094676818.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENow%20we%20have%20a%20single%20workbook%20with%20a%20unique%20sheet%2C%20called%20%22ATable%22%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_4-1628094930996.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300553i557A17AFDBD0A548%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_4-1628094930996.png%22%20alt%3D%22DamoBird365_4-1628094930996.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%20might%20you%20want%20to%20do%20this%3F%26nbsp%3B%20If%20you%20maintain%20a%20single%20workbook%20with%20multiple%20sheets%20and%20want%20to%20share%20a%20copy%20of%20each%20worksheet%20with%20individuals%20or%20teams%2C%20this%20would%20allow%20you%20to%20achieve%20that%20without%20compromising%20the%20original%20file.%26nbsp%3B%20You%20could%20routinely%20split%20up%20your%20workbook%20and%20send%20a%20copy%20of%20each%20worksheet%20to%20your%20colleagues%20via%20email%20or%20Teams.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWatch%20the%20full%20build%20and%20demonstration%20here%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIFRAME%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2F4ZiMjjV1c3Q%22%20width%3D%22560%22%20height%3D%22315%22%20frameborder%3D%220%22%20allowfullscreen%3D%22%22%20title%3D%22YouTube%20video%20player%22%20allow%3D%22accelerometer%3B%20autoplay%3B%20clipboard-write%3B%20encrypted-media%3B%20gyroscope%3B%20picture-in-picture%22%3E%3C%2FIFRAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20target%3D%22_blank%22%20name%3D%22emptyfile%22%3E%3C%2FA%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-295201592%22%20id%3D%22toc-hId-295201592%22%3ECreate%20an%20empty%20Excel%20File%3C%2FH2%3E%0A%3CP%3ENatively%2C%20PowerAutomate%20doesn't%20allow%20you%20to%20create%20a%20new%20Excel%20file.%26nbsp%3B%20By%20creating%20an%20empty%20Excel%20file%20on%20SharePoint%20and%20using%20the%20get%20file%20content%20action%2C%20it's%20possible%20to%20save%20the%20JSON%20output%20to%20a%20compose%20and%20re-use%20the%20empty%20template%20file%20when%20using%20the%20%22create%20file%22%20action.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_0-1628095727802.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300557i8DCA7977ACED62B5%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1628095727802.png%22%20alt%3D%22DamoBird365_0-1628095727802.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EA%20compose%20action%20with%20the%20File%20Content%20copied%20into%20it.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_1-1628095823450.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300558i865816494415A499%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_1-1628095823450.png%22%20alt%3D%22DamoBird365_1-1628095823450.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBy%20doing%20it%20this%20way%2C%20we%20achieve%20two%20things.%3C%2FP%3E%0A%3CP%3E1.%20no%20need%20for%20the%20donor%20empty%20excel%20file%2C%20we%20can%20delete%20it%20and%20not%20have%20to%20worry%20about%20it%20being%20deleted%20accidentally%3C%2FP%3E%0A%3CP%3E2.%20we%20can%20remove%20the%20get%20file%20content%20action%20and%20rely%20entirely%20on%20the%20compose%20action%20we%20have%20created%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20using%20the%20output%20of%20the%20compose%20action%20we%20can%20create%20a%20new%20file%20(in%20this%20case%20named%20with%20a%20unique%20datetime%20string%20formatdatetime(utcnow()%2C'yyyyMMddhhmmss').xlsx%20and%20then%20create%20a%20new%20table%20to%20allow%20data%20to%20be%20inserted.%26nbsp%3B%20Here%20we%20have%20a%20table%20range%20from%20column%20A%20to%20E%20on%20row%201%2C%20i.e.%205%20columns%20with%20headers%20Name%2C%20Age%2C%20Address1%2C%20Address2%2C%20PostCode.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_2-1628096048590.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300559i56B68BEA4CD3773A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_2-1628096048590.png%22%20alt%3D%22DamoBird365_2-1628096048590.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20populate%20our%20excel%20file%2C%20I%20have%20an%20array%20contained%20within%20a%20compose%2C%20this%20data%20array%20could%20be%20the%20result%20of%20another%20action%20or%20a%20filter%20or%20OData%20query%20on%20another%20Excel%20Worksheet%20that%20you%20simply%20want%20to%20save%20a%20copy%20of%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_4-1628096378139.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300561i1F60CDFD42058737%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_4-1628096378139.png%22%20alt%3D%22DamoBird365_4-1628096378139.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20using%20an%20apply%20to%20each%20and%20the%20compose%20array%20as%20an%20input%20we%20can%20add%20rows%20to%20the%20table%20and%20construct%20the%20row%20input%20array%20for%20our%20%22add%20a%20row%22%20action%20with%20keys%20%2F%20name%20pairs%20based%20on%20the%20column%20headers%20from%20the%20create%20table%20action.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22Name%22%3A%20%22%40%7Bitems('Apply_to_each')%3F%5B'Name'%5D%7D%22%2C%0A%20%20%22Age%22%3A%20%22%40%7Bitems('Apply_to_each')%3F%5B'Age'%5D%7D%22%2C%0A%20%20%22Address1%22%3A%20%22%40%7Bitems('Apply_to_each')%3F%5B'Address1'%5D%7D%22%2C%0A%20%20%22Address2%22%3A%20%22%40%7Bitems('Apply_to_each')%3F%5B'Address2'%5D%7D%22%2C%0A%20%20%22Postcode%22%3A%20%22%40%7Bitems('Apply_to_each')%3F%5B'Postcode'%5D%7D%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20table%20name%20is%20provided%20dynamically%20from%20the%20create%20table%20action%20and%20the%20File%20Id%20is%20the%20dynamic%20value%20from%20the%20create%20file%20action.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_3-1628096174072.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300560i90986028D875BB53%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_3-1628096174072.png%22%20alt%3D%22DamoBird365_3-1628096174072.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIf%20we%20turn%20on%20concurrency%2C%20we%20can%20add%2050%20rows%20to%20the%20newly%20created%20excel%20file%20in%20a%20matter%20of%20seconds.%26nbsp%3B%20Whilst%20I%20haven't%20covered%20this%20here%2C%20it%20would%20be%20possible%20to%20write%20an%20office%20script%20to%20take%20an%20array%20of%20objects%20and%20populate%20an%20excel%20file%20without%20a%20table.%26nbsp%3B%20I%20have%20previously%20covered%20this%20concept%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fmicrosoft-365-pnp-blog%2Fexcel-scripts-and-cloud-flows-data-manipulation%2Fba-p%2F2356956%22%20target%3D%22_blank%22%3EExcel%20Scripts%20and%20Cloud%20Flows%20-%20Data%20Manipulation%20-%20Microsoft%20Tech%20Community%3C%2FA%3E.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWatch%20how%20you%20can%20create%20a%20new%20file%20via%20PowerAutomate%20here%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIFRAME%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FRB_ySjhm9Sg%22%20width%3D%22560%22%20height%3D%22315%22%20frameborder%3D%220%22%20allowfullscreen%3D%22%22%20title%3D%22YouTube%20video%20player%22%20allow%3D%22accelerometer%3B%20autoplay%3B%20clipboard-write%3B%20encrypted-media%3B%20gyroscope%3B%20picture-in-picture%22%3E%3C%2FIFRAME%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1512252871%22%20id%3D%22toc-hId--1512252871%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CP%3E%3CA%20target%3D%22_blank%22%20name%3D%22csvtoexcel%22%3E%3C%2FA%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-975259962%22%20id%3D%22toc-hId-975259962%22%3EAnd%20Finally%2C%20converting%20a%20CSV%20to%20Excel%20File%3C%2FH2%3E%0A%3CP%3EAll%20we%20are%20doing%20is%20swapping%20out%20the%20array%20contained%20within%20the%20compose%20action%20and%20converting%20a%20CSV%20to%20an%20Array.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20we%20have%20a%20CSV%20contained%20within%20a%20compose%20and%20another%20compose%20action%20with%20a%20return%20line%20(literally%20press%20return%20on%20your%20keyboard).%26nbsp%3B%20Then%20using%20split%2C%20we%20turn%20the%20CSV%20into%20an%20array%20of%20separate%20lines.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_5-1628096964541.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300562i522EE586591513FB%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_5-1628096964541.png%22%20alt%3D%22DamoBird365_5-1628096964541.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20the%20select%20action%2C%20the%20from%20array%20input%20is%20the%20output%20from%20the%20compose%20splitline%20array%20(skipping%20object%20one%2C%20which%20contains%20the%20header%20line)%20and%20in%20this%20case%20I%20have%20supplied%20the%20key%20names%20manually.%26nbsp%3B%20Finally%20the%20expression%20used%20to%20obtain%20the%20value%20is%20a%20split%20of%20each%20item%20(Or%20line)%20based%20on%20the%20separator%2C%20the%20comma%20'%2C'.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20will%20allow%20us%20to%20call%20each%20value%20by%20integer%20index%26nbsp%3B%3CEM%3Esplit(item()%2C'%2C')%5B0%5D.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_6-1628097127838.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300563i025AC0D58B708C7D%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_6-1628097127838.png%22%20alt%3D%22DamoBird365_6-1628097127838.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EOur%20select%20action%20take%20an%20array%20of%20comma%20separated%20lines%20and%20outputs%20an%20array%20of%20key%2Fvalue%20pairs%20like%20follows%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_7-1628097240857.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300564iAD353590D0D2B6E7%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_7-1628097240857.png%22%20alt%3D%22DamoBird365_7-1628097240857.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20if%20we%20update%20the%20apply%20to%20each%20source%20as%20the%20select%20output%2C%20we%20end%20up%20with%20a%20new%20excel%20file%20using%20a%20CSV%20file%20as%20our%20input%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_8-1628097338222.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300565i877F08A627FB14B3%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_8-1628097338222.png%22%20alt%3D%22DamoBird365_8-1628097338222.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20more%20information%20about%20parsing%20CSV%20files%20in%20PowerAutomate%2C%20please%20read%20my%20blog%20article%20%3CA%20href%3D%22https%3A%2F%2Fwww.damobird365.com%2Fhow-to-parse-a-csv-to-json-array-flow%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EHow%20To%20Parse%20any%20CSV%20to%20JSON%20Array%20-%20DamoBird365%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMore%20ideas%20and%20concepts%20on%20my%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC-NCKrEw6CM8fidaIk-yrUQ%3Fsub_confirmation%3D1%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EYouTube%3C%2FA%3E%20or%20%3CA%20href%3D%22http%3A%2F%2Fwww.damobird365.com%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EBlog%3C%2FA%3E.%26nbsp%3B%20Please%20feel%20free%20to%20reach%20out%20if%20you%20have%20any%20questions.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2611337%22%20slang%3D%22en-US%22%3E%3CP%3EHave%20you%20ever%20wanted%20to%20split%20a%20workbook%20with%20multiple%20worksheets%20into%20multiple%20unique%20workbooks%20or%20create%20a%20new%20excel%20file%20for%20that%20data%20you've%20retrieved%20from%20an%20action%3F%26nbsp%3B%20Maybe%20convert%20a%20CSV%20to%20an%20Excel%20file%3F%26nbsp%3B%20Let%20me%20show%20you%20how%20this%20can%20be%20done%20easily%20using%20Power%20Automate%20and%20where%20necessary%2C%20a%20bit%20of%20Office%20Scripts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22DamoBird365_0-1628098378685.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F300566i8752603604D1C474%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1628098378685.png%22%20alt%3D%22DamoBird365_0-1628098378685.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Co-Authors
Version history
Last update:
‎Aug 04 2021 11:03 AM
Updated by: