Excel Scripts and Cloud Flows - Data Manipulation

Published May 17 2021 12:50 AM 2,521 Views
Senior Member

Capture.PNG

 

Have you discovered that the existing Power Automate actions for Excel are limited to Excel Tables?  Are you looking to take your cloud flow interactions with Excel to the next level?  Maybe it's time to start looking at Excel Scripts which are currently accessible to Power Automate as a Preview Feature.

 

What are Excel Scripts?  Using either the built in recording tool or TypeScript programming language you can create a script to update cells, rows or ranges of data or indeed insert formulas into cells.  You can even use Excel to perform some of the features missing to Power Automate like sorting an array.

 

I have prepared a two part video series demo'ing how you can use Power Automate and Excel Scripts to both send data to a plain excel file and populate cells, rows and ranges but also in return, again using Excel Scripts, how you can create a table in an Excel file and return the available data either as a results array for your next action in your Cloud Flow OR by using the list all rows action based on the newly created table.  

 

First Video on Populating Excel from Cloud Flows is available here:

 

 

The below Cloud Flow is relatively straight forward for this first part demo.  We have an array of Rows for our Excel Worksheet and this demonstrates one of many ways to pass data to Excel via the Script Action.  The real benefit of creating a bespoke function in Excel Scripts is that the Script Action is dynamic.  It will return the fields you have defined in the action window and ensure the datatype provided is correct, i.e. string or number.

 

DamoBird365_0-1621076762535.png

 

In the sample Typescript Excel Script built below, you can try this for yourself.  The script will populate unique cells, columns and rows with data based on the 4 variable types defined, examplevar1-4 as strings, numbers, multivariables and arrays.

 

 

function main(workbook: ExcelScript.Workbook,

  examplevar1: string,
  examplevar2: number,
  examplevar3: multivariable, //Header of Table
  examplevar4: arrayvar[] //Multiple rows in Table

) {

  let selectedSheet = workbook.getActiveWorksheet();
  
  // Set cells A1,B2,C3,D4 on selectedSheet
  selectedSheet.getRange("A1").setValue(examplevar1);
  selectedSheet.getRange("B2").setValue(examplevar2);
  selectedSheet.getRange("C3").setValue(examplevar1 + ' ' + examplevar2);
  selectedSheet.getRange("D4").setValue(examplevar2 + 1111);

  //An example function to reverse the strings
  function reverseString(str: string) {
    return str.split("").reverse().join("");
  }

  //Create Vertical Header Row with Multi Variables
  const formattedColumn = [
    [reverseString(examplevar3.multivar3var1)], 
    [reverseString(examplevar3.multivar3var2)],
    [reverseString(examplevar3.multivar3var3)],
    [reverseString(examplevar3.multivar3var4)],
    [reverseString(examplevar3.multivar3var5)],
    [reverseString(examplevar3.multivar3var6)]];

  selectedSheet.getRange("F1:F6").setValues(formattedColumn);

  //Create Horizontal Header Row with Multi Variables 
  const formattedHeader = [[examplevar3.multivar3var1, examplevar3.multivar3var2, examplevar3.multivar3var3, examplevar3.multivar3var4, examplevar3.multivar3var5, examplevar3.multivar3var6]];
    
  selectedSheet.getRange("A8:F8").setValues(formattedHeader);

  //Populate rows below Header Row with Array Variable 
  const starterrow = 9; //starting row for "table" data
  
  for (let i = 0; i < examplevar4.length; i++) {
    const currentObject = examplevar4[i];

    const formattedrow = [[currentObject.arr4var1, currentObject.arr4var2, currentObject.arr4var3, currentObject.arr4var4, currentObject.arr4var5, currentObject.arr4var6,]];

    const rowRange = `A${starterrow + i}:F${starterrow + i}`;
    selectedSheet.getRange(rowRange).setValues(formattedrow);
  }

  //Return a response to the Cloud Flow
  return "DamoBird365 Loaded " + examplevar4.length + " Records Loaded into Excel and Demo Completed OK"
}

//Defining Interfaces for MultiVar and Array

interface multivariable {
  multivar3var1: string,
  multivar3var2: string,
  multivar3var3: string,
  multivar3var4: string,
  multivar3var5: string,
  multivar3var6: string
}

interface arrayvar {
  arr4var1: number,
  arr4var2: string,
  arr4var3: string,
  arr4var4: string,
  arr4var5: string,
  arr4var6: string
}

 

 

Second video on retrieving data back from Excel files without a table.  Identify the active cells, define and create a table via the script and return the data to your cloud flow as either a result to the script action or via the traditional list rows actions.

 

 

The Cloud flow on this occasion does not require any data input as its purpose is to return data back to the flow.  Whilst the data could be fully repurposed in Excel, as a Power Automate enthusiast, I have used a select action to reformat the Array and rename the keys.  Both the Select Action and the List Rows Action demonstrate the two methods for retrieving data from Excel where no table was present previously.

 

DamoBird365_1-1621076794170.png

 

Again, in the sample Typescript Excel Script built below, you can quickly test out the functionality of creating a table and returning data to your cloud flow.  The code is commented to help you understand how the solution is built.  Please note I am not a coder but with the available resources online, I was quickly able to understand how to put this together.  The recording tool is also useful for getting an understanding of some of the functions available.

 

 

function main(workbook: ExcelScript.Workbook) {

  // Get the first worksheet 
  const selectedSheet = workbook.getFirstWorksheet();

  //get active range of WorkSheet
  let range = workbook.getActiveWorksheet().getUsedRange();

  // Get last used row of WorkSheet
  let lastrow = range.getRowCount();

  // Find first reference of ID in selectedSheet i.e. header row
  let IDCell = selectedSheet.getRange("A1").find("ID", { completeMatch: true, matchCase: true, searchDirection: ExcelScript.SearchDirection.forward });

  // Get the current active cell in the workbook.
  //and format current cell without Sheet1! reference
  let activeCell = IDCell.getAddress().replace("Sheet1!", "");

  //get table range  
  const TableRange = `${activeCell}:F${lastrow}`;

  // Create a table using the data range.
  let newTable = workbook.addTable(selectedSheet.getRange(TableRange), true);
  newTable.setName("NewTableInExcel");

  // Get the first (and only) table in the worksheet.
  let table = selectedSheet.getTables()[0];

  // Get the data from the table.
  let tableValues = table.getRange().getValues();

  //Return a response to the Cloud Flow
  return tableValues

}

 

 

Where do you find Excel Scripts Functionality?  It's an Excel Online feature.  Load up Excel and click on the Automate Tab.  Here you can view all scripts, record some actions and edit new or existing scripts that have been built.

 

DamoBird365_0-1621236507649.png

 

Wondering where they live?  Jump onto OneDrive and take a look at Documents/Office Scripts where you can export/import and share.

 

DamoBird365_1-1621236596024.png

 

Want to see a proof of concept ?  Take a look at my Invoicing Demo here where I show you how you could autocompete an excel invoice template using scripts.  I recently covered this in a live demo with the Monthly (12th May) Microsoft Office Scripts Dev Team and included a bonus feature, converting the excel files to PDF using the same flow without premium actions.  Look out for this video on here soon.

 

Please let me know if you found this useful and what you might use Excel Scripts for next.

2 Comments
%3CLINGO-SUB%20id%3D%22lingo-sub-2356956%22%20slang%3D%22en-US%22%3EExcel%20Scripts%20and%20Cloud%20Flows%20-%20Data%20Manipulation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2356956%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Capture.PNG%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F281007i368C3E73001AFF26%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Capture.PNG%22%20alt%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHave%20you%20discovered%20that%20the%20existing%20Power%20Automate%20actions%20for%20Excel%20are%20limited%20to%20Excel%20Tables%3F%26nbsp%3B%20Are%20you%20looking%20to%20take%20your%20cloud%20flow%20interactions%20with%20Excel%20to%20the%20next%20level%3F%26nbsp%3B%20Maybe%20it's%20time%20to%20start%20looking%20at%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fintroduction-to-office-scripts-in-excel-9fbe283d-adb8-4f13-a75b-a81c6baf163a%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExcel%20Scripts%3C%2FA%3E%20which%20are%20currently%20accessible%20to%20Power%20Automate%20as%20a%20Preview%20Feature.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat%20are%20Excel%20Scripts%3F%26nbsp%3B%20Using%20either%20the%20built%20in%20recording%20tool%20or%20TypeScript%20programming%20language%20you%20can%20create%20a%20script%20to%20update%20cells%2C%20rows%20or%20ranges%20of%20data%20or%20indeed%20insert%20formulas%20into%20cells.%26nbsp%3B%20You%20can%20even%20use%20Excel%20to%20perform%20some%20of%20the%20features%20missing%20to%20Power%20Automate%20like%20%3CA%20href%3D%22https%3A%2F%2Fwww.tachytelic.net%2F2021%2F04%2Fpower-automate-sort-array-objects%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Esorting%20an%20array%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20prepared%20a%20two%20part%20video%20series%20demo'ing%20how%20you%20can%20use%20Power%20Automate%20and%20Excel%20Scripts%20to%20both%20send%20data%20to%20a%20plain%20excel%20file%20and%20populate%20cells%2C%20rows%20and%20ranges%20but%20also%20in%20return%2C%20again%20using%20Excel%20Scripts%2C%20how%20you%20can%20create%20a%20table%20in%20an%20Excel%20file%20and%20return%20the%20available%20data%20either%20as%20a%20results%20array%20for%20your%20next%20action%20in%20your%20Cloud%20Flow%20OR%20by%20using%20the%20list%20all%20rows%20action%20based%20on%20the%20newly%20created%20table.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EFirst%20Video%3C%2FSTRONG%3E%20on%20Populating%20Excel%20from%20Cloud%20Flows%20is%20available%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%2FQ7GLQnvJJF0%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%3EThe%20below%20Cloud%20Flow%20is%20relatively%20straight%20forward%20for%20this%20first%20part%20demo.%26nbsp%3B%20We%20have%20an%20array%20of%20Rows%20for%20our%20Excel%20Worksheet%20and%20this%20demonstrates%20one%20of%20many%20ways%20to%20pass%20data%20to%20Excel%20via%20the%20Script%20Action.%26nbsp%3B%20The%20real%20benefit%20of%20creating%20a%20bespoke%20function%20in%20Excel%20Scripts%20is%20that%20the%20Script%20Action%20is%20dynamic.%26nbsp%3B%20It%20will%20return%20the%20fields%20you%20have%20defined%20in%20the%20action%20window%20and%20ensure%20the%20datatype%20provided%20is%20correct%2C%20i.e.%20string%20or%20number.%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-1621076762535.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280853iF746EEC5EF6A49E0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1621076762535.png%22%20alt%3D%22DamoBird365_0-1621076762535.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20sample%20Typescript%20Excel%20Script%20built%20below%2C%20you%20can%20try%20this%20for%20yourself.%26nbsp%3B%20The%20script%20will%20populate%20unique%20cells%2C%20columns%20and%20rows%20with%20data%20based%20on%20the%204%20variable%20types%20defined%2C%20examplevar1-4%20as%20strings%2C%20numbers%2C%20multivariables%20and%20arrays.%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%0A%20%20examplevar1%3A%20string%2C%0A%20%20examplevar2%3A%20number%2C%0A%20%20examplevar3%3A%20multivariable%2C%20%2F%2FHeader%20of%20Table%0A%20%20examplevar4%3A%20arrayvar%5B%5D%20%2F%2FMultiple%20rows%20in%20Table%0A%0A)%20%7B%0A%0A%20%20let%20selectedSheet%20%3D%20workbook.getActiveWorksheet()%3B%0A%20%20%0A%20%20%2F%2F%20Set%20cells%20A1%2CB2%2CC3%2CD4%20on%20selectedSheet%0A%20%20selectedSheet.getRange(%22A1%22).setValue(examplevar1)%3B%0A%20%20selectedSheet.getRange(%22B2%22).setValue(examplevar2)%3B%0A%20%20selectedSheet.getRange(%22C3%22).setValue(examplevar1%20%2B%20'%20'%20%2B%20examplevar2)%3B%0A%20%20selectedSheet.getRange(%22D4%22).setValue(examplevar2%20%2B%201111)%3B%0A%0A%20%20%2F%2FAn%20example%20function%20to%20reverse%20the%20strings%0A%20%20function%20reverseString(str%3A%20string)%20%7B%0A%20%20%20%20return%20str.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%7D%0A%0A%20%20%2F%2FCreate%20Vertical%20Header%20Row%20with%20Multi%20Variables%0A%20%20const%20formattedColumn%20%3D%20%5B%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var1)%5D%2C%20%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var2)%5D%2C%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var3)%5D%2C%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var4)%5D%2C%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var5)%5D%2C%0A%20%20%20%20%5BreverseString(examplevar3.multivar3var6)%5D%5D%3B%0A%0A%20%20selectedSheet.getRange(%22F1%3AF6%22).setValues(formattedColumn)%3B%0A%0A%20%20%2F%2FCreate%20Horizontal%20Header%20Row%20with%20Multi%20Variables%20%0A%20%20const%20formattedHeader%20%3D%20%5B%5Bexamplevar3.multivar3var1%2C%20examplevar3.multivar3var2%2C%20examplevar3.multivar3var3%2C%20examplevar3.multivar3var4%2C%20examplevar3.multivar3var5%2C%20examplevar3.multivar3var6%5D%5D%3B%0A%20%20%20%20%0A%20%20selectedSheet.getRange(%22A8%3AF8%22).setValues(formattedHeader)%3B%0A%0A%20%20%2F%2FPopulate%20rows%20below%20Header%20Row%20with%20Array%20Variable%20%0A%20%20const%20starterrow%20%3D%209%3B%20%2F%2Fstarting%20row%20for%20%22table%22%20data%0A%20%20%0A%20%20for%20(let%20i%20%3D%200%3B%20i%20%26lt%3B%20examplevar4.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20const%20currentObject%20%3D%20examplevar4%5Bi%5D%3B%0A%0A%20%20%20%20const%20formattedrow%20%3D%20%5B%5BcurrentObject.arr4var1%2C%20currentObject.arr4var2%2C%20currentObject.arr4var3%2C%20currentObject.arr4var4%2C%20currentObject.arr4var5%2C%20currentObject.arr4var6%2C%5D%5D%3B%0A%0A%20%20%20%20const%20rowRange%20%3D%20%60A%24%7Bstarterrow%20%2B%20i%7D%3AF%24%7Bstarterrow%20%2B%20i%7D%60%3B%0A%20%20%20%20selectedSheet.getRange(rowRange).setValues(formattedrow)%3B%0A%20%20%7D%0A%0A%20%20%2F%2FReturn%20a%20response%20to%20the%20Cloud%20Flow%0A%20%20return%20%22DamoBird365%20Loaded%20%22%20%2B%20examplevar4.length%20%2B%20%22%20Records%20Loaded%20into%20Excel%20and%20Demo%20Completed%20OK%22%0A%7D%0A%0A%2F%2FDefining%20Interfaces%20for%20MultiVar%20and%20Array%0A%0Ainterface%20multivariable%20%7B%0A%20%20multivar3var1%3A%20string%2C%0A%20%20multivar3var2%3A%20string%2C%0A%20%20multivar3var3%3A%20string%2C%0A%20%20multivar3var4%3A%20string%2C%0A%20%20multivar3var5%3A%20string%2C%0A%20%20multivar3var6%3A%20string%0A%7D%0A%0Ainterface%20arrayvar%20%7B%0A%20%20arr4var1%3A%20number%2C%0A%20%20arr4var2%3A%20string%2C%0A%20%20arr4var3%3A%20string%2C%0A%20%20arr4var4%3A%20string%2C%0A%20%20arr4var5%3A%20string%2C%0A%20%20arr4var6%3A%20string%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%3CSTRONG%3ESecond%20video%3C%2FSTRONG%3E%20on%20retrieving%20data%20back%20from%20Excel%20files%20without%20a%20table.%26nbsp%3B%20Identify%20the%20active%20cells%2C%20define%20and%20create%20a%20table%20via%20the%20script%20and%20return%20the%20data%20to%20your%20cloud%20flow%20as%20either%20a%20result%20to%20the%20script%20action%20or%20via%20the%20traditional%20list%20rows%20actions.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CIFRAME%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FUspiIlj6hSQ%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%3EThe%20Cloud%20flow%20on%20this%20occasion%20does%20not%20require%20any%20data%20input%20as%20its%20purpose%20is%20to%20return%20data%20back%20to%20the%20flow.%26nbsp%3B%20Whilst%20the%20data%20could%20be%20fully%20repurposed%20in%20Excel%2C%20as%20a%20%3CSTRONG%3EPower%20Automate%20enthusiast%3C%2FSTRONG%3E%2C%20I%20have%20used%20a%20select%20action%20to%20reformat%20the%20Array%20and%20rename%20the%20keys.%26nbsp%3B%20Both%20the%20Select%20Action%20and%20the%20List%20Rows%20Action%20demonstrate%20the%20two%20methods%20for%20retrieving%20data%20from%20Excel%20where%20no%20table%20was%20present%20previously.%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-1621076794170.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F280854iCAA66655C04C0872%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DamoBird365_1-1621076794170.png%22%20alt%3D%22DamoBird365_1-1621076794170.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAgain%2C%20in%20the%20sample%20Typescript%20Excel%20Script%20built%20below%2C%20you%20can%20quickly%20test%20out%20the%20functionality%20of%20creating%20a%20table%20and%20returning%20data%20to%20your%20cloud%20flow.%26nbsp%3B%20The%20code%20is%20commented%20to%20help%20you%20understand%20how%20the%20solution%20is%20built.%26nbsp%3B%20Please%20note%20I%20am%20not%20a%20coder%20but%20with%20the%20available%20resources%20online%2C%20I%20was%20quickly%20able%20to%20understand%20how%20to%20put%20this%20together.%26nbsp%3B%20The%20recording%20tool%20is%20also%20useful%20for%20getting%20an%20understanding%20of%20some%20of%20the%20functions%20available.%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%0A%20%20%2F%2F%20Get%20the%20first%20worksheet%20%0A%20%20const%20selectedSheet%20%3D%20workbook.getFirstWorksheet()%3B%0A%0A%20%20%2F%2Fget%20active%20range%20of%20WorkSheet%0A%20%20let%20range%20%3D%20workbook.getActiveWorksheet().getUsedRange()%3B%0A%0A%20%20%2F%2F%20Get%20last%20used%20row%20of%20WorkSheet%0A%20%20let%20lastrow%20%3D%20range.getRowCount()%3B%0A%0A%20%20%2F%2F%20Find%20first%20reference%20of%20ID%20in%20selectedSheet%20i.e.%20header%20row%0A%20%20let%20IDCell%20%3D%20selectedSheet.getRange(%22A1%22).find(%22ID%22%2C%20%7B%20completeMatch%3A%20true%2C%20matchCase%3A%20true%2C%20searchDirection%3A%20ExcelScript.SearchDirection.forward%20%7D)%3B%0A%0A%20%20%2F%2F%20Get%20the%20current%20active%20cell%20in%20the%20workbook.%0A%20%20%2F%2Fand%20format%20current%20cell%20without%20Sheet1!%20reference%0A%20%20let%20activeCell%20%3D%20IDCell.getAddress().replace(%22Sheet1!%22%2C%20%22%22)%3B%0A%0A%20%20%2F%2Fget%20table%20range%20%20%0A%20%20const%20TableRange%20%3D%20%60%24%7BactiveCell%7D%3AF%24%7Blastrow%7D%60%3B%0A%0A%20%20%2F%2F%20Create%20a%20table%20using%20the%20data%20range.%0A%20%20let%20newTable%20%3D%20workbook.addTable(selectedSheet.getRange(TableRange)%2C%20true)%3B%0A%20%20newTable.setName(%22NewTableInExcel%22)%3B%0A%0A%20%20%2F%2F%20Get%20the%20first%20(and%20only)%20table%20in%20the%20worksheet.%0A%20%20let%20table%20%3D%20selectedSheet.getTables()%5B0%5D%3B%0A%0A%20%20%2F%2F%20Get%20the%20data%20from%20the%20table.%0A%20%20let%20tableValues%20%3D%20table.getRange().getValues()%3B%0A%0A%20%20%2F%2FReturn%20a%20response%20to%20the%20Cloud%20Flow%0A%20%20return%20tableValues%0A%0A%7D%0A%0A%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%3CSTRONG%3EWhere%20do%20you%20find%20Excel%20Scripts%20Functionality%3F%3C%2FSTRONG%3E%26nbsp%3B%20It's%20an%20Excel%20Online%20feature.%26nbsp%3B%20Load%20up%20Excel%20and%20click%20on%20the%20Automate%20Tab.%26nbsp%3B%20Here%20you%20can%20view%20all%20scripts%2C%20record%20some%20actions%20and%20edit%20new%20or%20existing%20scripts%20that%20have%20been%20built.%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-1621236507649.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F281004i15807D706F28766B%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DamoBird365_0-1621236507649.png%22%20alt%3D%22DamoBird365_0-1621236507649.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EWondering%20where%20they%20live%3F%3C%2FSTRONG%3E%26nbsp%3B%20Jump%20onto%20OneDrive%20and%20take%20a%20look%20at%20Documents%2FOffice%20Scripts%20where%20you%20can%20export%2Fimport%20and%20share.%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-1621236596024.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F281005iF9129292C1DC059D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22DamoBird365_1-1621236596024.png%22%20alt%3D%22DamoBird365_1-1621236596024.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWant%20to%20see%20a%20proof%20of%20concept%20%3F%26nbsp%3B%20Take%20a%20look%20at%20my%20Invoicing%20Demo%20%3CA%20href%3D%22https%3A%2F%2Fdamobird365.birdhoose.co.uk%2F2021%2F03%2F24%2Fpower-automate-office-scripts-populate-an-excel-template-dynamically-using-type-script%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20where%20I%20show%20you%20how%20you%20could%20autocompete%20an%20excel%20invoice%20template%20using%20scripts.%26nbsp%3B%20I%20recently%20covered%20this%20in%20a%20live%20demo%20with%20the%20Monthly%20(12th%20May)%20Microsoft%20Office%20Scripts%20Dev%20Team%20and%20included%20a%20bonus%20feature%2C%20converting%20the%20excel%20files%20to%20PDF%20using%20the%20same%20flow%20without%20premium%20actions.%26nbsp%3B%20Look%20out%20for%20this%20video%20on%20%3CA%20href%3D%22https%3A%2F%2Fwww.youtube.com%2Fc%2FMicrosoft365Developer%2Fvideos%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E%20soon.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20let%20me%20know%20if%20you%20found%20this%20useful%20and%20what%20you%20might%20use%20Excel%20Scripts%20for%20next.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2356956%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22lia-align-center%22%3E%3CSPAN%3EHow%20to%20populate%20an%20excel%20file%20that%20doesn't%20contain%20a%20table%20using%20Excel%20Scripts.%26nbsp%3B%20Populate%20individual%20cells%2C%20ranges%20or%20rows.%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-center%22%3E%3CSPAN%3EAnd%20in%20reverse%3F%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%20class%3D%22lia-align-center%22%3E%3CSPAN%3EHow%20to%20retrieve%20data%20from%20excel%20with%20no%20table%3F%20Learn%20how%3C%2FSPAN%3E%26nbsp%3Bto%20create%20a%20table%20and%20retrieve%20data%20dynamically%20back%20to%20your%20cloud%20flow.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2356956%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%20Scripts%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2370381%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20Scripts%20and%20Cloud%20Flows%20-%20Data%20Manipulation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2370381%22%20slang%3D%22en-US%22%3E%3CP%3EVery%20useful!%20Power%20automate%20is%20extremely%20powerful.%20With%20Office%20Scripts%2C%20too%2C%20it%20makes%20it%20an%20invincible%20combination!!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2670449%22%20slang%3D%22de-DE%22%3ESubject%3A%20Excel%20Scripts%20and%20Cloud%20Flows%20-%20Data%20Manipulation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2670449%22%20slang%3D%22de-DE%22%3E%3CP%3EDifferent%20results%20of%20the%20calculation%20when%20using%20now()%20in%20the%20formulas.%3C%2FP%3E%3CP%3ERun%20A%20Script%20local%20in%20excel%3C%2FP%3E%3CP%3EB%20Script%20via%20Automaten%20Flow%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eno%20solution%20known%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎May 17 2021 12:42 AM
Updated by: