单词阅读CustomXmlParts间歇性卡住

时间:2016-10-08 21:52:23

标签: office-addins office-js

环境:Mac Office 2016 build 15.26

我正在阅读Word文档' Office.initialize完成后的CustomXmlParts。我使用的是Office.context.document.customXmlParts.getByNamespaceAsync API。 getByNamespaceAsync间歇性地卡住。只要我单击Word文档,API就会恢复并成功读取CustomXmlParts。

围绕这个做什么工作?我也尝试调用context.document.getSelection来模仿光标点击,但没有帮助。

Office.context.document.customXmlParts.getByNamespaceAsync("MyXmlTag", function (asyncResult) {
                            if (asyncResult.value.length > 0) {
                                asyncResult.value[0].getNodesAsync("/", function (asyncNodeResult) {
                                    if (asyncNodeResult.status == Office.AsyncResultStatus.Failed) {
                                        console.log(" Failed to read word document.  " + JSON.stringify(asyncResult));

                                   } else {
                                        asyncNodeResult.value[0].getNodeValueAsync(function (result) {
                                            if (result.status == Office.AsyncResultStatus.Failed) {
                                                console.log(" getNodeValueAsync: Failed " + JSON.stringify(asyncResult));
                                            }
                                            else {
                                                //result.valuse is xml data
                                            }
                                        });
                                    }
                                });
                            }
                            else {
                                console.log(" CustomXML part is not found");
                            }
                        });

`

1 个答案:

答案 0 :(得分:0)

感谢您报告此问题。我还没有能够在内部重现它。一些问题:

  • 当你说你运行这段代码"在Office.initialize完成"之后,你的意思是它在你的Office.initialize回调代码里面(还在$(document).ready里面,所以它是在HTML / JS完成加载后执行的,还是完全独立的代码?您的代码是如何触发的?
  • 问题出现在您尝试过的所有自定义XML中,还是仅出现在特定的自定义XML中?