Linked Questions

Popular Questions

Get checkbox values in docx file using python

Asked by At

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:name w:val="MyCheck"/>
    <w:calcOnExit w:val="0"/>
        <w:default w:val="1"/>

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')))



Unable to determine if the checkbox is set

Related Questions