wordpress hit counter
Re: Removing the blank placeholder text for unused content controls - WordprocessingML - Formats - OpenXML Developer

Re: Removing the blank placeholder text for unused content controls

Formats

Discussions about working with different Open XML Formats

Removing the blank placeholder text for unused content controls

  • rated by 0 users
  • This post has 1 Reply |
  • 1 Follower
  • Hi there

    I'm working on an application that needs to populate template documents with data so I'm using Content Controls.

    Not all of the content controls will get populated each time so I need to remove the "Click here to enter text" - or whatever the default text is for that document.  I don't have control over the template document - we only specify what values can be used for the content control tags.

    I've worked out from the xml that the docPart referenced in the placeholder child of the sdt element refers to a docPart in the glossaryDocument elsewhere in the docx file but I can't quite get my head around what properties I'm looking for when using the SDK.

    This is the xml for the content control:

    <w:sdt>
    	<w:sdtPr>
    		<w:alias w:val="Home Phone"/>
    		<w:tag w:val="HOMETELEPHONE"/>
    		<w:id w:val="94051074"/>
    		<w:placeholder>
    			<w:docPart w:val="DefaultPlaceholder_22675703"/>
    		</w:placeholder>
    		<w:showingPlcHdr/>
    		<w:text/>
    	</w:sdtPr>
    	<w:sdtContent>
    		<w:r w:rsidR="001C20C3" w:rsidRPr="00542DD4">
    			<w:rPr>
    				<w:rStyle w:val="PlaceholderText"/>
    			</w:rPr>
    			<w:t>Click here to enter text.</w:t>
    		</w:r>
    	</w:sdtContent>
    </w:sdt>
    

    and this is from the word\glossary\document.xml

    <w:glossaryDocument
    	 <w:docParts>
    		<w:docPart>
    			<w:docPartPr>
    				<w:name w:val="DefaultPlaceholder_22675703"/>
    				<w:category>
    					<w:name w:val="General"/>
    					<w:gallery w:val="placeholder"/>
    				</w:category>
    				<w:types>
    					<w:type w:val="bbPlcHdr"/>
    				</w:types>
    				<w:behaviors>
    					<w:behavior w:val="content"/>
    				</w:behaviors>
    				<w:guid w:val="{D50A6C71-4CCD-428C-8E6D-357FB733C956}"/>
    			</w:docPartPr>
    			<w:docPartBody>
    				<w:p w:rsidR="005B3E04" w:rsidRDefault="00AA6D30">
    					<w:r w:rsidRPr="00542DD4">
    						<w:rPr>
    							<w:rStyle w:val="PlaceholderText"/>
    						</w:rPr>
    						<w:t>Click here to enter text.</w:t>
    					</w:r>
    				</w:p>
    			</w:docPartBody>
    		</w:docPart>
    	</w:docParts>
    </w:glossaryDocument>
    

    I noticed that the same value "DefaultPlaceholder_22675703" appears in both, and also both refer to rsidRPr value of "00542DD4".

    I could probably get it working using xpath statements using one or both of those values  but I'd like to use the open xml SDK.

  • I guess this is probably a little late...

    Interesting find -- the glossary.xml. Don't you which there was some sort of reference where you could look these things up?  

    In any case, what we've done in the past is to simply eliminate any w:t nodes within the w:sdtContent node (that references blank data).

Page 1 of 1 (2 items)