2

I have a check box in word docx file. I am able to identify when a checkbox is present but I am not able to retrieve the w:default value (See below where the default value is 1 which means the check box is set)

<w:ffData>
    <w:name w:val="MyCheck"/>
    <w:enabled/>
    <w:calcOnExit w:val="0"/>
    <w:checkBox>
        <w:sizeAuto/>
        <w:default w:val="1"/>
    </w:checkBox>
</w:ffData>

Using the following code I only get "None" returned for the checkbox value (w:val) and default value (w:default)- any ideas how I can access these values for each checkbox?

from docx import Document
from docx.oxml.ns import qn

document = Document('C:\MyTest\\onecheckbox.docx')

doc_elm = document._element
checkBoxes = doc_elm.xpath('.//w:checkBox')
for checkBox in checkBoxes:
    print('checkBox value is %s' % checkBox.get(qn('w:val')))
    print('default value is %s' % checkBox.get(qn('w:default')))

Thanks

J

Unable to determine if the checkbox is set

1
  • Looks like this is based on outdated xml. Please see this SO for an updated. Commented Aug 8, 2024 at 20:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.