Text in docx (OpenXML SDK generated) uneditable in Word

Answered Text in docx (OpenXML SDK generated) uneditable in Word

  • Wednesday, March 21, 2012 1:37 AM
     
      Has Code

    I created a docx document using OpenXML SDK. It contains group content controls to be able to have a nested document structure. The group content controls can contain other group content controls or normal text paragraphs or both. The structure of the resulting document.xml is something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">   
        <w:body>  
            <w:sectPr>  
                <w:pgSz w:w="12240" w:h="15840"/><w:pgMar w:gutter="0" w:footer="720" w:header="720" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/>  
                <w:cols w:space="720"/><w:docGrid w:linePitch="360"/>  
            </w:sectPr>  
            <w:sdt>  
                <w:sdtPr>  
                    <w:alias w:val="deel"/>  
                    <w:tag w:val="deel"/>  
                    <w:lock w:val="unlocked"/>  
                    <w:group/>  
                </w:sdtPr>  
                <w:sdtContent>  
                    <w:p>  
                        <w:pPr>  
                            <w:pStyle w:val="DeelTitel"/>  
                            <w:tabs>  
                                <w:tab w:val="clear" w:pos="360"/>  
                                <w:tab w:val="num" w:pos="1987"/>  
                            </w:tabs>  
                        </w:pPr>  
                        <w:r>  
                            <w:t>Some paragraph text here</w:t>  
                        </w:r>  
                    </w:p>  
                    <w:sdt>  
                        <w:sdtPr>  
                            <w:alias w:val="hoofdstuk"/>  
                            <w:tag w:val="hoofdstuk"/>  
                            <w:lock w:val="unlocked"/>  
                            <w:group/>  
                        </w:sdtPr>  
                        <w:sdtContent>  
                        <w:p>  
                            <w:pPr>  
                                <w:pStyle w:val="HoofdstukTitel"/>  
                                <w:tabs>  
                                    <w:tab w:val="clear" w:pos="360"/>  
                                    <w:tab w:val="num" w:pos="1987"/>  
                                </w:tabs>  
                            </w:pPr>  
                            <w:r>  
                                <w:t>Another title here one level deeper</w:t>  
                             </w:r>  
                         </w:p>
    etc. etc.

    The result looks good in Word, but the problem is that all the text seems to be locked. As you can see in the XML above I tried setting the lock property of the SdtBlocks to value "unlocked". I also tried leaving the whole lock property out, but all with the same result: if I try to edit one of the titles in the paragraphs Word displays the error "this modification is not allowed because the selection is locked".

    Am I doing something wrong here or how can I make sure the text in the paragraphs is editable?

    Thanks in advance.

    Ruben.


All Replies

  • Thursday, March 22, 2012 1:40 AM
     
     Answered

    In case someone else needs this in the future, I figured out what the culprit was. Leaving out the w:group in the sdt properties (sdtPr) resolves this problem. From the documentation: "This element specifies that the parent structured document tag shall be a restricted grouping when displayed in the document." So it actually makes sense, but it was hard to figure out. Hope it saves someone else some precious time in the future.

    Ruben.

  • Thursday, March 22, 2012 4:52 AM
    Moderator
     
     

    Hi Ruben,

    I'm glad to hear you have figured it out. Thanks for sharing your experience here. It's very beneficial for other commmunity members who have similar questions to see how you solved your issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us