Javascript word-win32-16.00.js:19:150094中的一般异常错误\n位于yi
我有一个大约100字的开放式XML(.XML,而不是.docx,另存为“Word XML文档”)文档(组件)存储在SharePoint上 我使用AJAX通过选择将它们作为xml以1对多的形式加载到一个数组中,在这个数组中我还管理选择序列 一旦用户选择了“组件”,他们就可以将它们插入Word中,插入是通过数组遍历完成的(可能有更好的方法可以做到这一点,但目前它确实有效) wordBuild进行加载Javascript word-win32-16.00.js:19:150094中的一般异常错误\n位于yi,javascript,jquery,sharepoint-2013,office365api,office-js,Javascript,Jquery,Sharepoint 2013,Office365api,Office Js,我有一个大约100字的开放式XML(.XML,而不是.docx,另存为“Word XML文档”)文档(组件)存储在SharePoint上 我使用AJAX通过选择将它们作为xml以1对多的形式加载到一个数组中,在这个数组中我还管理选择序列 一旦用户选择了“组件”,他们就可以将它们插入Word中,插入是通过数组遍历完成的(可能有更好的方法可以做到这一点,但目前它确实有效) wordBuild进行加载 function writeDocSync(){ // run through nameXMLA
function writeDocSync(){
// run through nameXMLArray to find the right sequence
var x = 0;
var countXMLAdds = 0;
//debugger;
toggleWriteButton("disable");
$('.progress-button').progressInitialize("Building Word");
toggleProgressBar(true);
// only run if we have data present
if(nameXMLArray.length > 0){
// increment through sequentially until we have all values
while (countXMLAdds <= checkedList.length){
// repeatedly traverse the array to get the next in sequence
while (x < nameXMLArray.length){
if (Number(nameXMLArray[x].position) === countXMLAdds && nameXMLArray[x].useStatus === true){
progHold = countXMLAdds;
wordBuild(nameXMLArray[x].xml, nameXMLArray[x].filename, countXMLAdds);
}
x++;
}
x=0;
countXMLAdds ++;
}
document.getElementById("showCheck").className = "results";
writeSelections("<b>You just built your proposal using<br/>the following components:</b><br/>");
toggleWriteButton("enable");
}
}
所有文档都将单独加载,并且都将以批量加载,例如10-30或更多
当我加载整个集合时就会出现问题(我有一个“全选”选项)。
有时在我得到一个异常之前会生成50个,有时是60个,很少超过60个,但非常偶尔我会在异常没有发生的地方得到一个间隙,然后它会在以后继续
异常(对每个文件重复)是:
调试信息:{}
错误:componentABC.xml:{“name”:“OfficeExtension.Error”,“code”:“GeneralException”,“message”:“发生了内部错误”,“traceMessages”:[],“debugInfo”:{},“stack”:“GeneralException:发生了内部错误。\n在匿名函数中(https://customerportal.sharepoint.com/sites/components/Shared%20Documents/componentAssembler/Scripts/Office/1/word-win32-16.00.js:19:150094)\n在易(https://customerportal.sharepoint.com/sites/components/Shared%20Documents/componentAssembler/Scripts/Office/1/word-win32-16.00.js:19:163912)\n在圣彼得堡(https://customerportal.sharepoint.com/sites/components/Shared%20Documents/componentAssembler/Scripts/Office/1/word-win32-16.00.js:19:163999)\n位于d(https://customerportal.sharepoint.com/sites/components/Shared%20Documents/componentAssembler/Scripts/Office/1/word-win32-16.00.js:19:163819)\n位于c(https://customerportal.sharepoint.com/sites/components/Shared%20Documents/componentAssembler/Scripts/Office/1/word-win32-16.00.js:19:162405)}
任何可能导致这种情况的帮助都将不胜感激
哦,我还应该说,引发异常的文件不会被插入Word中。但是,在较小的批处理中,它们可以正常工作。Word.run()
是一个异步调用,并且对您可以进行的并发Word.run()
调用的数量有限制。因为您正在执行Word.run()
在一个循环中,当
循环时,所有循环同时启动并同时运行
有几种方法可以解决这个问题
Word.run()
call中。这将所有内容放在一个大批量中,避免多次往返调用Word
if (nameXMLArray.length > 0 {
Word.run(function(context) {
//...
while(...) {
wordBuild(context, nameXMLArray[x].xml, nameXMLArray[x].filename, countXMLAdds);
//...
}
return context.sync();
});
}
function wordBuild(context, xmlBoxy, nameDoc, progress) {
//everything as it currently is, except without the Word.run and the context.sync
}
function wordBuild(...) {
var deferred = $q.defer();
Word.run( function(context) {
// current code
return context.sync().then(function() {
deferred.resolve();
});
});
return deferred.promise;
}
//Somewhere else
for (var x…)
{
promises.add(wordBuild);
}
$q.all(promises);
var x = 0;
var context;
function (wordBuild() {
if (x >= nameXMLArray.length)
return;
else {
context.document.body.insertOoxml(ooxml, Word.InsertLocation.end);
x++;
return context.sync().then(wordBuild);
}
});
Word.run(function (ctx) {
context = ctx;
return wordBuild();
}
$q
wordBuild
调用自己,如下所示:
function wordBuild(...) {
var deferred = $q.defer();
Word.run( function(context) {
// current code
return context.sync().then(function() {
deferred.resolve();
});
});
return deferred.promise;
}
//Somewhere else
for (var x…)
{
promises.add(wordBuild);
}
$q.all(promises);
var x = 0;
var context;
function (wordBuild() {
if (x >= nameXMLArray.length)
return;
else {
context.document.body.insertOoxml(ooxml, Word.InsertLocation.end);
x++;
return context.sync().then(wordBuild);
}
});
Word.run(function (ctx) {
context = ctx;
return wordBuild();
}
这种方法很难维持,但可以奏效顺便说一句,原始代码中的进度表仅在Word调用开始时更新,而不是在实际返回时更新。您可能希望将进度表更新代码移到回调中。我最终使用了jQuery延迟,我已经在使用jQuery for treeview和复选框等。因此这很有意义 这是Geoffrey的建议和我自己的建议的混合!我不能说它是好代码,只是它确实有效。(如果它是好代码或不是好代码,我需要更多的时间来理解!) 我在异步调用“Word.run”时运行了49个xml文档插入的批处理测试失败,一个Word.run中插入了80个左右的文档,导致Word冻结,因此,尽管没有证明1个Word中有49个插入。run似乎是10的良好开端!50个插入49个片段可以插入2450个插入,这远远超出了我所能看到的任何需要,并且可能会破坏Word 为了让延迟和发送的变量在作为异步延迟启动时保持其值,我必须创建一个变量来传输新的延迟和值,这样我就可以使用“bind”命令。 当Word async返回context.sync()时,我会检查批处理的计数,当批处理完成后,我会调用下一个批处理-在context.sync()内 一种递归调用,仍然是Geoffrey的建议和批处理的组合。这在理论上限制为50批49个文档节。到目前为止,这在所有测试中都有效 进度表存在于它自己的定时调用中,但由于JavaScript将代码优先于UI,它确实会跳跃。例如,120个文档,它会以相当快的速度跳到一半以下,然后一段时间后跳到几乎完成,然后完成(实际上,快速连续百分比增加了3跳,建议的各种技巧没有任何效果(forceRepaint()是最新的实验!)
函数startUILock(){
//以49份文件为一组进行批处理(51份及更多文件显示失败,49份给了manouvre空间)
切换进度条(真);
$('.progress按钮').progressInitialize(“构建Word”);
进度计。进度集(1);
$.blockUI({消息:“构建单词…”});
设置超时(强制重新绘制,3000);
}
函数forceRepaint(){
var el=document.getElementById('progDiv');
el.style.cssText+=';-webkit变换:rotateZ(0度)';
远视;
el.style.cssText+=';-webkit转换:无';
}
函数UIUnlock(插入计数){
调试器;
var pct=(insertedCount/checkedList.length)*100
//showNotification(“进度百分比为:”+pct);
如果(insertedCount!==checkedList.length){
进度计。进度集(pct);
forceRepaint();
}否则{
$.unbui();
progressMeter.prog