[英]Office Add-in: Cannot clean Word document after inserting ooxml (Office Online, works on Desktop)
第一次插入后,尝试替换Word文档的内容。 当我运行此代码时:
Word.run(async context => {
let range = context.document.body.getRange();
let myContentControl = range.insertContentControl();
myContentControl.clear();
myContentControl.insertOoxml(ooxml, Word.InsertLocation.replace);
myContentControl.cannotEdit = false;
myContentControl.cannotDelete = false;
context.load(myContentControl, "id");
await context.sync();
});
我收到此错误:
NotAllowed Word Online中不支持该操作。 检查
OfficeExtension.Error.debugInfo
以获取更多信息。
如果我使用文本,然后运行此代码,它插入正常。
这可能是我的ooxml
吗?
如果没有看到OOXML或OfficeExtension.Error.debugInfo
的值,就很难知道问题出在哪里。
也就是说,你在这里做了很多不必要的步骤:
Word.run(async context => {
let range = context.document.body.getRange();
// Why insert a content control?
let myContentControl = range.insertContentControl();
// Since you just inserted this, there nothing to clear
myContentControl.clear();
// Similar, since this is new (and cleared) why "replace"
myContentControl.insertOoxml(ooxml, Word.InsertLocation.replace);
// Already the default value
myContentControl.cannotEdit = false;
myContentControl.cannotDelete = false;
// Why load this when you're not doing anything
// with the value you're loaded
context.load(myContentControl, "id");
// Little known tip/trick:
// You don't need to sync here, Word.run() will automatically
// process anything in the queue when it completes
await context.sync();
});
在尝试诊断这是否是您的OOXML字符串之前,我首先要减少您所做的不需要的调用次数:
Word.run(async context => {
let range = context.document.body.getRange();
range.insertOoxml('Your OOXML', 'Replace');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.