问题描述
我正在处理从 Word365 网络加载项单击自定义功能区栏按钮的功能。
由于此过程涉及多个对话框,因此我在清单文件中使用操作类型“ExecuteFunction
”来单击功能区栏按钮。
在功能区栏按钮“工作流程”上单击,“附加”对话框应打开。该对话框中有一个名为“附加”的按钮。它应该打开一个服务器浏览对话框,所选的服务器文件将返回一个 json,我需要将其转换为 xml 并存储在 document.CustomXmlParts
中,因为它应该保存为文档特定值。
我还没有开始服务器浏览部分。我试图在 document.CustomXmlParts
中存储一些示例 xml 作为测试尝试。但是我无法访问 Office.context.document.CustomXmlParts
,它给出了错误“Unable to get property 'customXmlParts' of undefined or null reference
”。但是当我尝试在 FunctionFile.js 中访问 Office.context.document.CustomXmlParts
时,我可以保存 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>
FunctionFile.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();
}
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)