'How to avoid adding content controller within a content controller
As a user when he/she tries to add a content control we would like to validate that if a content controller is already there as a parent ?
Our Environment
- Platform [PC desktop, Mac, iOS, Office on the web]: Office on the web and desktop Office
- Host [Excel, Word, PowerPoint, etc.]: Word
- Operating System: Windows 10 Pro
- Browser (if using Office on the web): Chrome Version 101.0.4951.54 (Official Build) (64-bit)/ Edge Version 101.0.1210.39 (Official build) (64-bit) / Microsoft® Word for Microsoft 365 MSO (Version 2204 Build 16.0.15128.20158) 64-bit
Expected behavior
As a user when he/she tries to add a content controller we would like to validate that if a content controller is already there as a parent ?
Current behavior
We are unable to validate whether content control is there as parent or not ?
Context
Our application relies heavily on inserting content into the document and we support both browser and desktop office.
await Word.run(async context => {
const rngDoc = context.document.getSelection();
const ooxml = `<pkg:package
xmlns:pkg='http://schemas.microsoft.com/office/2006/xmlPackage'>
<pkg:part pkg:name='/_rels/.rels' pkg:contentType='application/vnd.openxmlformats-package.relationships+xml'>
<pkg:xmlData>
<Relationships
xmlns='http://schemas.openxmlformats.org/package/2006/relationships'>
<Relationship Id='rId1' Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' Target='word/document.xml'/>
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name='/word/document.xml' pkg:contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml'>
<pkg:xmlData>
<w:document
xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' >
<w:body>
<w:p>
<w:sdt>
<w:sdtPr>
<w:lock w:val="unlocked"/>
<w:alias w:val="${item?.alias}" />
<w:tag w:val="<Tag><Xpath>${item?.xpath}</Xpath></Tag>" />
<w:showingPlcHdr />
<w:dataBinding w:prefixMappings="xmlns:ns0='abc'" w:xpath="${item?.xpath}" w:storeItemID="{00000000-0000-0000-0000-000000000000}" />
<w:text/>
</w:sdtPr>
<w:sdtContent>
<w:r>
<w:rPr>
<w:color w:val="808080" w:themeShade="80" />
</w:rPr>
<w:t>${item?.placeHolder}</w:t>
</w:r>
</w:sdtContent>
</w:sdt>
</w:p>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>`;
rngDoc.insertOoxml(ooxml, Word.InsertLocation.after);
return context.sync();
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
