在我的Excel加载项中,我使用Dialog API向用户显示消息。显示并关闭对话框,不会出现任何问题或错误。
当对话框关闭时,用户无法通过单击单元格并编写来编辑工作表中的单元格。
如果用户双击某个单元格,则此功能将再次返回(对于所有单元格)。
以下是控制对话框的代码:
var app = (function (app) {
var dialog;
// Show dialog
app.showNotification = function (header, text) {
if (Office.context.requirements.isSetSupported('DialogApi', 1.1)) {
var dialogUrl = window.location.href.substring(0,
window.location.href.lastIndexOf('/') + 1) +
"AppMessage.html?msg=" + text + "&title=" + header;
Office.context.ui.displayDialogAsync(dialogUrl, {
height: 20,
width: 20,
displayInIframe: true
},
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived,
processMessage);
});
}
};
function processMessage(arg) {
if (arg.message == "close")
dialog.close();
}
return app;
})(app || {});
和对话框代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/css/fabric.min.css">
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/css/fabric.components.min.css">
<script src="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-js/1.4.0/js/fabric.min.js"></script>
</head>
<body>
<span class="ms-font-xl ms-fontWeight-semibold" id="titleMain"></span>
<p class="ms-font-m" id="body"></p>
<button class="ms-Button ms-Button--primary" style="position:fixed;bottom:10px;right:10px;" onclick="closeDialog();">
<span class="ms-Button-label">OK</span>
</button>
<script src="appMessage.js"></script>
</body>
</html>
这是appMessage.js
内容
var urlParams;
Office.initialize = function () {};
//avoiding the usage of jquery in this small page
window.$ = function (selector) {
return document.querySelector(selector);
};
function closeDialog() {
Office.context.ui.messageParent("close");
}
(window.onpopstate = function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) {
return decodeURIComponent(s.replace(pl, " "));
},
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
$("#titleMain").innerHTML = urlParams["title"];
$("#body").innerHTML = urlParams["msg"];
})();
有什么不对?
由于