Excel 加载项自定义功能未在 Excel 在线加载

Excel Add-Ins custom functions not loaded in Excel on-line

加载项自定义函数在桌面上运行良好,但在在线加载时抛出 CORS 错误Excel:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xl.celin.io/assets/functions.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

检查是否为 add-in 的服务器配置了 CORS header“Access-Control-Allow-Origin”。例如,在yo office创建的样本add-in中,webpack.config.js中有如下字段:

devServer: {
      ...,
      headers: {
        "Access-Control-Allow-Origin": "*",
      },
      ...
    },