Excel自定义函数未显示
Excel Custom Function is not shown
我正在 Office 加载项中创建一个 Excel 自定义函数。我的起点是 Visual Studio 2017 年脚手架。
在我的清单中我有
<FunctionFile resid="Contoso.DesktopFunctionFile.Url" />
哪里
<bt:Url id="Contoso.DesktopFunctionFile.Url" th:DefaultValue="${baseUrl+'/Functions/FunctionFile.html'}" />
FunctionFile.html
是Visual Studio
生成的文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<script src="FunctionFile.js" type="text/javascript"></script>
</head>
<body>
<!-- NOTA: il corpo è intenzionalmente vuoto. Dal momento che viene richiamato tramite un pulsante, non esiste interfaccia utente di cui eseguire il rendering. -->
</body>
</html>
然后在 FunctionFile.js
中我输入
(function () {
Office.initialize = function (reason) {
function sum(var1, var2){
return var1+var2;
}
};
})();
Excel 忽略函数“sum”,但我的插件的其他功能有效。
FunctionFile.js
在 Office.initialize
中是定义自定义函数的正确位置吗?
在哪里可以为我的函数设置命名空间?
经过一些测试,我发现了这个解决方法
我的清单文件是这样的
<AllFormFactors>
<ExtensionPoint xsi:type="CustomFunctions">
<Script>
<SourceLocation resid="Functions.Script.Url"/>
</Script>
<Page>
<SourceLocation resid="Functions.Page.Url"/>
</Page>
<Metadata>
<SourceLocation resid="Functions.Metadata.Url"/>
</Metadata>
<Namespace resid="Functions.Namespace"/>
</ExtensionPoint>
</AllFormFactors>
AllFormFacotrs 介于
<Host xsi:type="Workbook">
...
</Host>
functionFile.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Expires" content="0" />
<title></title>
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/custom-functions-runtime.js" type="text/javascript"></script>
<script src="functionFile.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
funciton.json 类似于
{
"functions": [
{
"description": "Calculates the volume of a sphere.",
"id": "SPHEREVOLUME",
"name": "SPHEREVOLUME",
"parameters": [
{
"name": "radius",
"type": "number"
}
],
"result": {}
}
]
}
最后真正的代码变成了 ender functionFile.js
var funcs = {};
funcs['SPHEREVOLUME'] = function(raggio){
return 444*raggio;
};
//ugly code
! function(e) {
var t = {};
function n(o) {
if (t[o])
return t[o].exports;
var r = t[o] = { i: o, l: !1, exports: {} };
return e[o].call(r.exports, r, r.exports, n), r.l = !0, r.exports
}
n.m = e, n.c = t, n.d = function(e, t, o) { n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: o }) }, n.r = function(e) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }) }, n.t = function(e, t) {
if (1 & t && (e = n(e)), 8 & t) return e;
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
var o = Object.create(null);
if (n.r(o), Object.defineProperty(o, "default", { enumerable: !0, value: e }), 2 & t && "string" != typeof e)
for (var r in e) n.d(o, r, function(t) { return e[t] }.bind(null, r));
return o
}, n.n = function(e) { var t = e && e.__esModule ? function() { return e.default } : function() { return e }; return n.d(t, "a", t), t }, n.o = function(e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, n.p = "", n(n.s = 1)
}(
{
1: function(e, t) {
Object.entries(funcs).forEach(([key, value]) => {
CustomFunctions.associate(''+key, value);
});
//CustomFunctions.associate("SPHEREVOLUME", funcs['SPHEREVOLUME']);
}
}
);
什么“丑代码”是你生成的一段代码我无法清理
这样的函数
可见。
我正在 Office 加载项中创建一个 Excel 自定义函数。我的起点是 Visual Studio 2017 年脚手架。
在我的清单中我有
<FunctionFile resid="Contoso.DesktopFunctionFile.Url" />
哪里
<bt:Url id="Contoso.DesktopFunctionFile.Url" th:DefaultValue="${baseUrl+'/Functions/FunctionFile.html'}" />
FunctionFile.html
是Visual Studio
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title></title>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<script src="FunctionFile.js" type="text/javascript"></script>
</head>
<body>
<!-- NOTA: il corpo è intenzionalmente vuoto. Dal momento che viene richiamato tramite un pulsante, non esiste interfaccia utente di cui eseguire il rendering. -->
</body>
</html>
然后在 FunctionFile.js
中我输入
(function () {
Office.initialize = function (reason) {
function sum(var1, var2){
return var1+var2;
}
};
})();
Excel 忽略函数“sum”,但我的插件的其他功能有效。
FunctionFile.js
在 Office.initialize
中是定义自定义函数的正确位置吗?
在哪里可以为我的函数设置命名空间?
经过一些测试,我发现了这个解决方法
我的清单文件是这样的
<AllFormFactors>
<ExtensionPoint xsi:type="CustomFunctions">
<Script>
<SourceLocation resid="Functions.Script.Url"/>
</Script>
<Page>
<SourceLocation resid="Functions.Page.Url"/>
</Page>
<Metadata>
<SourceLocation resid="Functions.Metadata.Url"/>
</Metadata>
<Namespace resid="Functions.Namespace"/>
</ExtensionPoint>
</AllFormFactors>
AllFormFacotrs 介于
<Host xsi:type="Workbook">
...
</Host>
functionFile.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Expires" content="0" />
<title></title>
<script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/custom-functions-runtime.js" type="text/javascript"></script>
<script src="functionFile.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
funciton.json 类似于
{
"functions": [
{
"description": "Calculates the volume of a sphere.",
"id": "SPHEREVOLUME",
"name": "SPHEREVOLUME",
"parameters": [
{
"name": "radius",
"type": "number"
}
],
"result": {}
}
]
}
最后真正的代码变成了 ender functionFile.js
var funcs = {};
funcs['SPHEREVOLUME'] = function(raggio){
return 444*raggio;
};
//ugly code
! function(e) {
var t = {};
function n(o) {
if (t[o])
return t[o].exports;
var r = t[o] = { i: o, l: !1, exports: {} };
return e[o].call(r.exports, r, r.exports, n), r.l = !0, r.exports
}
n.m = e, n.c = t, n.d = function(e, t, o) { n.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: o }) }, n.r = function(e) { "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }) }, n.t = function(e, t) {
if (1 & t && (e = n(e)), 8 & t) return e;
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
var o = Object.create(null);
if (n.r(o), Object.defineProperty(o, "default", { enumerable: !0, value: e }), 2 & t && "string" != typeof e)
for (var r in e) n.d(o, r, function(t) { return e[t] }.bind(null, r));
return o
}, n.n = function(e) { var t = e && e.__esModule ? function() { return e.default } : function() { return e }; return n.d(t, "a", t), t }, n.o = function(e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, n.p = "", n(n.s = 1)
}(
{
1: function(e, t) {
Object.entries(funcs).forEach(([key, value]) => {
CustomFunctions.associate(''+key, value);
});
//CustomFunctions.associate("SPHEREVOLUME", funcs['SPHEREVOLUME']);
}
}
);
什么“丑代码”是你生成的一段代码我无法清理
这样的函数
可见。