0

We have been moving towards writing office scripts instead of VBA macros. I am also aware of the Microsoft Graph REST APIs for excel. Can someone guide me how can I execute an office script (like a sample one below) programmatically without creating an excel instance locally?


async function main(context: Excel.RequestContext) {
  // Set range A1 on selectedSheet
  let workbook = context.workbook;
  let worksheets = workbook.worksheets;
  let selectedSheet = worksheets.getActiveWorksheet();
  selectedSheet.getRange("A1").values = [
    ["Hello World"]
  ];
}

I could not find any graph api to do so.

Thanks.

Yutao Huang
  • 1,503
  • 1
  • 13
  • 25
Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
  • 1
    Yes, that could be done by either taking the user credentials before hand and generate the access token using the OAuth2 api's but I am also sure that the excel graph api's would in future support application permissions like other resources do. The problem is there is no API to run an office script. Are you saying there would be in near future to do so @RaymondLu? – Andy Dufresne Jun 08 '20 at 13:51

2 Answers2

2

To run office script via Graph API, there would be two requirements: 1. Office JS library: parse the office script to build the request and also parse the result in response. 2. Specific Graph API: run the request in service side against the target file.

Unfortunately, none of them is availabe now.

However, there is another ongoing work to integrate Office Scripts with PowerAutomate, which will enable us to run the scripts against a workbook on PowerAutomate (without a local Excel instance). Here (https://mybuild.microsoft.com/sessions/bc1bc3e6-9dc1-474e-a5d6-409af2fa0ad3?source=sessions) is the video to introduce Office Scripts (and also its integration with PowerAutomate) in recent Microsoft Build. This feature would be in public preview soon.

Joe Zhao
  • 46
  • 2
  • 2
    There is an ongoing work to integrate Office Scripts with PowerAutomate, which will enable us to run the scripts against a workbook on PowerAutomate (without a local Excel instance). Here (https://mybuild.microsoft.com/sessions/bc1bc3e6-9dc1-474e-a5d6-409af2fa0ad3?source=sessions) is the video to introduce Office Scripts (and also its integration with PowerAutomate) in recent Microsoft Build. This feature would be in public preview soon. – Joe Zhao Jun 10 '20 at 05:51
  • 1
    That's great @Joe Zhao. If you could convert your notes from the comment to the post, I could accept it as an answer. – Andy Dufresne Jun 10 '20 at 12:36
  • 1
    I merged the comments to my previous answer. – Joe Zhao Jun 11 '20 at 01:12
2

Microsoft has announced the Office Scripts integration with Microsoft Power Automate (preview), where you can run your Office Scripts with schedule-based triggers or event-based triggers.

Here are a few links that might be helpful:

Yutao Huang
  • 1,503
  • 1
  • 13
  • 25