我正在尝试使用Office JS创建Word加载项,该加载项将查看当前打开的文档中的内容,然后创建一个新文档并写入此新文档。这是我要执行的操作的代码段:
var myNewDoc = context.application.createDocument();
context.load(myNewDoc);
var body = myNewDoc.body;
body.insertText('some text', Word.InsertLocation.end);
但是当我运行它时,出现以下错误:
Debug info: {"code":"NotAllowed","message":"The action isn’t supported in Word Online. Check the OfficeExtension.Error.debugInfo for more information.","errorLocation":"DocumentCreated.body","statement":"var body=createDocument.body;","surroundingStatements":["var v=Microsoft.WordServices.Application.newObject();","var createDocument=v.createDocument();","// Instantiate {createDocument}","// >>>>>","var body=createDocument.body;","// <<<<<","// Instantiate {body}"],"fullStatements":["Please enable config.extendedErrorLogging to see full statements."]}
是否正在写入不是当前活动文档的文档?我认为,如果允许我们创建一个新文档,那么我们应该能够对其进行写操作。