use of w:tag in Office openxml/javascript add-in

Mark Nicholas Grimshaw-Aagaard 1 Reputation point
2021-02-12T10:58:47.463+00:00

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?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
994 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,963 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.