2

Due to the office API limitation ( API is only restricted to rich text content controls). We had to insert content controls as an OOXML object. It inserted the content control correctly but office API doesn’t recognize that as a content control. For example, using office API, if you call a method to get all the content controls, above content control will not be returned.

If you run following code, it will not return those content controls that were inserted like that.

// Run a batch operation against the Word object model.
Word.run(function (context) {  
     // Create a proxy object for the content controls collection.
     var contentControls = context.document.contentControls;
}

Here is the 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:padding="512">
            <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" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml">
                <w:body>
                <w:sdt>
                    <w:sdtPr>
                    <w:alias w:val="[REPLACE_THIS]" />
                    <w:id w:val="1382295294" />
                    <w:placeholder>
                        <w:docPart w:val="4D926923E99F45DBAF2203E4FEA73047" />
                    </w:placeholder>
                    <w:dataBinding w:xpath="[REPLACE_THIS]" w:storeItemID="{AFE97E21-6B3F-435F-8566-BD38F346ABE4}" />
                    <w:showingPlcHdr />
                    </w:sdtPr>
                    <w:sdtContent>
                    <w:p>
                        <w:r>
                        <w:t>[REPLACE_THIS]</w:t>
                        </w:r>
                    </w:p>
                    </w:sdtContent>
                </w:sdt>
                </w:body>
            </w:document>
            </pkg:xmlData>
        </pkg:part>
        </pkg:package>

As Office API doesn't have any built-in methods to get these content controls and modify them. I have to read each section of the document, Get the OOXML , modify it and insert it back. Is there any other way to do this ? As this is really cumbersome and error-prone process.

Imran Khan
  • 117
  • 2
  • 11

1 Answers1

0

I am assuming that you are using OOXML to insert other types of content controls (i.e. plain text, combo, date, etc.) and if that's the case, yes, in the content control collection we do not support, as of now, other types of content controls other than rich text. This is mostly because of a limitation in Word Online who only supports rich text as of today, and we ship APIs that can guarantee a multiplatform behavior. The plan is that when it eventually supports other types they will be included as part of the collection (hence the type property). so, yes for now your only way out is to get the OOXML and handle the other types of control via XML. You can probably target the OOXML you get if you wrap them with a rich text content control and only getting the OOXML of the wrapper content controls.

Juan Balmori
  • 4,898
  • 1
  • 8
  • 17
  • I have the same problem, too, and I really want to avoid patching the complete OOXML of the whole document for performance and stability reasons. Wrapping the content control is no option for me, as there are existing documents and other software expects that there is nothing wrapped. This type of content controls can't be edited by the user in Word Online anyway, so there is already a difference to the native Word application. Enabling this for Word for Mac would really help. – dominik May 31 '21 at 12:32