cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Impossibru28
Frequent Visitor

Office Script table to Sharepoint List

I have an Office Script that creates a table in an Excel sheet, and I am trying to add the rows from that table to a Sharepoint list. Is this possible? When I try to build the flow, the field value for Table is blank since the table technically doesn't exist until the script finishes running.

 

 

Impossibru28_0-1621007874258.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Impossibru28 

 

I've done a couple of videos this morning to cover both scenarios. 

 

How to load data into excel that doesn't contain a table using excel scripts

and

How to retrieve data from excel in 2 ways, create a table and returning a result using excel scripts.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

 

View solution in original post

4 REPLIES 4
DamoBird365
Microsoft
Microsoft

Hi @Impossibru28 

 

You can use a single script like follows:

 

function main(workbook: ExcelScript.Workbook) {
  
  // Get the first worksheet 
  const sheet = workbook.getFirstWorksheet();
  
  //get active range of WorkSheet
  let range = workbook.getActiveWorksheet().getUsedRange();

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

  //get table range  
  const TableRange = `A9:L${lastrow}`;

  // Create a table using the data range.
  let newTable = workbook.addTable(sheet.getRange(TableRange), true);
  newTable.setName("TestTable");
  
  // Get the first (and only) table in the worksheet.
  let table = sheet.getTables()[0];

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

  console.log(lastrow);
  return tableValues

}

 

Not only does it create a table but it returns the table as an array.  You can take your pick to either use the results from the script action or call the table using the get rows action.  In the example above it creates the table from A: row9 to L: last row in Sheet.  You can adjust this to fit your requirements.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

How can I call the table in the flow if it doesn't exist until the script action is completed? I also don't know how to get the rows from the newly created table and assign them to the appropriate fields in the Sharepoint list. 

Since the table doesn't exist until the script finishes running, what DamoBird365 is suggesting is to return the newly created table's values (aka the rows in the table) from the same Office Script you use to create the table. So you don't need the List rows present in a table step at all, you can return the table's values and operate on them the same way you would operate on the return value of List rows present in a table.

Hi @Impossibru28 

 

I've done a couple of videos this morning to cover both scenarios. 

 

How to load data into excel that doesn't contain a table using excel scripts

and

How to retrieve data from excel in 2 ways, create a table and returning a result using excel scripts.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

 

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (1,435)