I have the following:
Word.run(function (context) {
docSelection = context.document.getSelection();
var text = '<w:sdt><w:sdtPr><w:alias w:val="SomeAlias" /><w:tag w:val="SomeTag" /><w:lock w:val="sdtLocked" /></w:sdtPr>'
+ '<w:sdtContent><w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:pPr><w:pStyle w:val="NormalWeb" /></w:pPr>'
+ '<w:r><w:t>MY TEXT</w:t></w:r></w:p></w:sdtContent></w:sdt>';
docSelection.insertOoxml(text, "Replace");
return context.sync().then(function () {
console.log('Text insertion complete');
});
})
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
displayError(JSON.stringify(error));
return false;
}
});
Running this, I get the error: "Debug info: {"code":"GeneralException","message":"GeneralException","errorLocation":"Range.insertOoxml","statement":"var insertOoxml = selection.insertOoxml(...);","surroundingStatements":["var root = context.root;","var selection = root.getSelection();","// Instantiate {selection}","// >>>>>","var insertOoxml = selection.insertOoxml(...);","// <<<<<","// Instantiate {insertOoxml}"],"fullStatements":["var root = context.root;","var selection = root.getSelection();","// Instantiate {selection}","var insertOoxml = selection.insertOoxml("<w:sdt><w:sdtPr><w:alias w:val=\"SomeAlias\" /><w:tag w:val=\"SomeTag\" /><w:lock w:val=\"sdtLocked\" /></w:sdtPr><w:sdtContent><w:p xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:pPr><w:pStyle w:val=\"NormalWeb\" /></w:pPr><w:r><w:t>MY TEXT</w:t></w:r></w:p></w:sdtContent></w:sdt>", "Replace");","// Instantiate {insertOoxml}"]}"
which I quite simply don't understand.
Inserting with docSelection.insertOoxml("<w:p xmlns:w='http://schemas.microsoft.com/office/word/2003/wordml'><w:r><w:t>TEST</w:t></w:r></w:p>", "Replace");
works fine so the rest of my code is OK.
Any ideas what I'm doing wrong?