我正在从 Word365 Web 加载项单击自定义功能区栏按钮执行功能。由于此过程涉及多个对话框,因此我ExecuteFunction
在清单文件中使用操作类型“”来单击功能区栏按钮。
单击功能区栏按钮“工作流”后,应打开“附加”对话框。该对话框中有一个名为“附加”的按钮。它应该打开一个服务器浏览对话框,并且选择的服务器文件将返回一个 json,我需要将其转换为 xml 并存储在 中document.CustomXmlParts
,因为它应该保存为文档特定值。
我还没有开始服务器浏览部分。我正在尝试在其中存储一些示例 xmldocument.CustomXmlParts
作为测试尝试。但我无法访问Office.context.document.CustomXmlParts
,它给出了错误“ Unable to get property 'customXmlParts' of undefined or null reference
”。但是当我尝试Office.context.document.CustomXmlParts
在 FunctionFile.js 中访问时,我可以保存 xml 内容并成功检索它。
请帮我弄清楚到底是什么问题。
清单文件
<Control xsi:type="Button" id="Contoso.TaskpaneButton.AttachXML">
<Label resid="Contoso.FuntionAttachXML.Label" />
<Supertip>
<Title resid="Contoso.FuntionAttachXML.Label" />
<Description resid="Contoso.FuntionAttachXML.Tooltip" />
</Supertip>
<Icon>
<bt:Image size="16" resid="Contoso.TaskpaneButton.Icon" />
<bt:Image size="32" resid="Contoso.TaskpaneButton.Icon" />
<bt:Image size="80" resid="Contoso.TaskpaneButton.Icon" />
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>ShowAttachXMLDialog</FunctionName>
</Action>
</Control>
函数文件.js
// The initialize function must be run each time a new page is loaded.
(function () {
Office.initialize = function (reason) {
// If you need to initialize something you can do so here.
};
})();
var ShowAttachXMLDialog = function (event) {
try {
var dialogUrl = 'https://' + location.host + '/App/Dialogs/DlgAttach/DlgAttachXML.html';
Office.context.ui.displayDialogAsync(dialogUrl, { width: 60, height: 50, requireHTTPS: true }, function (asyncResult) {
if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
showAlert('editDlg', asyncResult.error.message);
} else {
_dialog = asyncResult.value;
}
});
} catch (e) {
showAlert(e.location, e.message);
}
}
DlgAttachXML.js 文件
(function () {
Office.initialize = function (reason) {
// If you need to initialize something you can do so here.
var doc = Office.context.document;
$(document).ready(function () {
thisDocument = document;
document.getElementById("attach-button").onclick = selectXMLFromServer;
});
};
})();
var selectXMLFromServer = function (event) {
//that sample xml I am trying to insert.
var xmlString = "<Reviewers xmlns='http://schemas.contoso.com/review/1.0'><Reviewer>Juan</Reviewer><Reviewer>Hong</Reviewer><Reviewer>Sally</Reviewer></Reviewers>";
//Error occurs in here
Office.context.document.customXmlParts.addAsync(xmlString,
(asyncResult) => {
Office.context.document.settings.set('AttachedXML', asyncResult.value.id);
Office.context.document.settings.saveAsync();
}
);
event.completed();
}
先感谢您。