Create selected checkbox in MS word document

I would like to add a selected checkbox in a word document .I have tried using the Dynamic Word Document smart service to add a checkbox but it didn't work out .

Also using the MS word template smart service I found out a way to add a checkbox using the code below:

"<w:p>
<w:pPr>
<w:pStyle w:val=""NoSpacing""/>
<w:spacing w:before=""40"" w:after=""40""/>
<w:jc w:val=""center""/>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
<w:fldChar w:fldCharType=""begin"">
<w:ffData>
<w:name w:val=""""/>
<w:enabled/>
<w:calcOnExit w:val=""0""/>
<w:checkBox>
<w:sizeAuto/>
<w:default w:val="&char(34)&if(true(),"1","0")&char(34)&"/>
</w:checkBox>
</w:ffData>
</w:fldChar>
</w:r>
<w:r>
<w:rPr>
<w:rFonts w:ascii=""Arial"" w:hAnsi=""Arial"" w:cs=""Arial""/>
<w:sz w:val=""20""/>
<w:szCs w:val=""20""/>
</w:rPr>
<w:instrText xml:space=""preserve""> FORMCHECKBOX </w:instrText>
</w:r>

</w:p>"

 

But this code does not create a checkbox in word all the time.( I get an error saying  error at line 0 column 0   word/document.xml)

Has anybody else tried and was able to add a selected checkbox in word document?

attached sample word document.

 

 

testDocumentCheckbox.docx

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Does it have to be a working checkbox, or do you just need to generate checked / unchecked boxes?

    This might seem like too much of a hack, but in case you would be OK with "dead" (i.e. not clickable) checkboxes, I have been using the following text strings perfectly for about 4 years now for our generated word documents:

    (unchecked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>o</w:t><w:t>

    (checked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>þ</w:t><w:t>

    Nevermind the fact that it changes the font to "Wingdings" to accomplish the affect - it looks really good and is sizeable. There might be a way to do this instead more straightforwardly with just Unicode character, but I haven't experimented with that yet.
    Hint: you can generate them in different sizes by changing the value of the "w:sz" tag. 24 ~ font size 12.

Reply
  • 0
    Certified Lead Developer

    Does it have to be a working checkbox, or do you just need to generate checked / unchecked boxes?

    This might seem like too much of a hack, but in case you would be OK with "dead" (i.e. not clickable) checkboxes, I have been using the following text strings perfectly for about 4 years now for our generated word documents:

    (unchecked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>o</w:t><w:t>

    (checked box)
    </w:t><w:rPr><w:rFonts w:ascii='Wingdings' w:hAnsi='Wingdings'/><w:sz w:val='24'/><w:szCs w:val='22'/></w:rPr><w:t>þ</w:t><w:t>

    Nevermind the fact that it changes the font to "Wingdings" to accomplish the affect - it looks really good and is sizeable. There might be a way to do this instead more straightforwardly with just Unicode character, but I haven't experimented with that yet.
    Hint: you can generate them in different sizes by changing the value of the "w:sz" tag. 24 ~ font size 12.

Children