1

We are currently implementing custom functions in our app, and have been unable to get POST requests working.

What we have tried:

  • POST using fetch (exact function works in latest Chrome)
  • POST using axios, and transpiling down (exact function works in latest Chrome)
  • Adding and removing cors() middleware on our backend expressjs server

Are we missing an implementation detail? I read something brief about simple CORS, but wanted to reach out to see if there was a piece we are forgetting.

Rick Kirkham
  • 9,038
  • 1
  • 14
  • 32
John Young
  • 27
  • 1
  • 6

2 Answers2

2

Are you testing on Excel for Windows, or Excel Online (aka Excel on the Web)? Currently full CORS is not supported yet in custom functions if you are running it in Excel for Windows. However it should work if you run it in Excel Online and Excel for Mac.

Wenbo Shi
  • 172
  • 4
  • 1
    Now the Shared Runtime is in preview and it should meet your requirements. [Overview: Run your add-in code in a shared JavaScript runtime (preview)](https://learn.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-shared-overview). Make sure the resource you access has CORS enabled. – Wenbo Shi Apr 18 '20 at 15:13
  • Hi there, the Shared Runtime is now Generally Available, so we suggest using that for CORS. thanks! – Keyur Patel - MSFT May 17 '20 at 18:15
1

I had this exact issue, I generated an excel add in using the yeoman generator and managed to make basic fetch requests, e.g using this famous example here: https://learn.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-web-reqs

However as soon as I added a headers field to a post fetch request my add in would fail on the windows version (but work fine on the web version).

As one of the comments mentions the answer is to make the plugin use the shared javascript runtime. Do I know what the shared javascript runtime is, or why Microsoft publishes documentation that doesn't work by default, no I do not to be honest I actually have really enjoyed most of the add in developer documentation but the web request stuff is a mess

Anyway if you follow the steps here: https://learn.microsoft.com/en-us/office/dev/add-ins/develop/configure-your-add-in-to-use-a-shared-runtime should work fine, at least it did for me.

nmu
  • 1,442
  • 2
  • 20
  • 40