2

我正在实现通过 POST 向外部 API 发出请求的 Office JS 自定义函数。目前,我在桌面上使用自定义函数运行时收到错误“网络错误”。

此错误仅在发送数据时发生(带有 axios 的数据配置选项)。发送时,data: undefined我收到一个成功的发布请求。Fetch/XMLHttp 给出同样的错误。这些发布请求在 excel Web 客户端上运行良好。

有问题的代码很简单:

    return axios.post('api endpoint', {...data})
        .then(response =>{ 
            console.log(response)
        });

函数.html

    <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/custom-functions-runtime.js" type="text/javascript"></script>

错误:

7/31/2019 8:38:59   Verbose Runtime [Console] [Log] Verbose CustomFunctions [Execution] [Begin] Function=IRR        
7/31/2019 8:38:59   Verbose Runtime [Console] [Log] Unexpected CustomFunctions [Execution] [End] [Failure] [RejectedPromise] Function=IRR Error: Network Error {"message":"Network Error","name":"Error","description":"Network Error","stack":"Error: Network Error\n   
at createError (C:\\Users\\{USER}\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{77465F27-AF7B-4EBF-B345-B511C35C4E42}\\vai+V16+KDygsa7v22t_6Q==\\Javascript\\fbcfcf48-d846-415b-9418-8278af45662f_1.0.0.0_en-US\\bundle.js:657:3)\n   
at handleError (C:\\Users\\{USER}\\AppData\\Local\\Microsoft\\Office\\16.0\\Wef\\{77465F27-AF7B-4EBF-B345-B511C35C4E42}\\vai+V16+KDygsa7v22t_6Q==\\Javascript\\fbcfcf48-d846-415b-9418-8278af45662f_1.0.0.0_en-US\\bundle.js:188:7)\n   
at dispatchEvent.value (foundation.win32.bundle:1:36516)\n   
at value (foundation.win32.bundle:1:111669)\n   
at value (foundation.win32.bundle:1:108416)\n   
at Anonymous function (foundation.win32.bundle:1:110776)\n   
at value (foundation.win32.bundle:1:61902)\n   
at value (foundation.win32.bundle:1:56068)\n   
at Anonymous function (foundation.win32.bundle:1:53578)\n   
at value (foundation.win32.bundle:1:55337)",
 "config":{
  "url":"{api endpoint}",
  "method":"post",
  "data":"{data i'm sending}",
  "headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"},
  "transformRequest":[null],
  "transformResponse":[null],
  "timeout":0,
  "xsrfCookieName":"XSRF-TOKEN",
  "xsrfHeaderName":"X-XSRF-TOKEN",
  "maxContentLength":-1}}       
7/31/2019 8:38:59   Unexpected  CustomFunctions [Execution] [Async] [End] [Failure] Function=IRR, Workbook=functionbug.xlsx     
4

1 回答 1

0

这可能是因为自定义函数尚不支持完整的 CORS。团队正在努力,应该很快就会在这里更新:

https://github.com/OfficeDev/office-js/issues/523

于 2019-08-03T14:58:26.483 回答