jeudi 10 novembre 2016

Cannot get the checkbox value from MS Word using Interop c#

I am trying to get the checkbox value from one .doc MS Word Document, reading it from .docx using OPENXML is easier because is implicit in the output XML:

<w:checkBox>
    <w:sizeAuto/>
    <w:default w:val=\"1\"/>
</w:checkBox>

But, with the output XML getting from Document.Content.XML using Interop is not possible, because the value is not implicit:

               <w:p wsp:rsidR=\"00040B2E\" wsp:rsidRPr=\"00A81C11\" wsp:rsidRDefault=\"00040B2E\" wsp:rsidP=\"001E040C\">
                        <w:pPr>
                            <w:spacing w:before=\"120\"/>
                            <w:rPr>
                                <w:rFonts w:ascii=\"Arial\" w:h-ansi=\"Arial\" w:cs=\"Arial\"/>
                                <wx:font wx:val=\"Arial\"/>
                                <w:sz w:val=\"18\"/>
                                <w:sz-cs w:val=\"18\"/>
                            </w:rPr>
                        </w:pPr>
                        <w:r wsp:rsidRPr=\"00A81C11\">
                            <w:rPr>
                                <w:rFonts w:ascii=\"Arial\" w:h-ansi=\"Arial\"/>
                                <wx:font wx:val=\"Arial\"/>
                                <w:b/>
                                <w:sz w:val=\"18\"/>
                                <w:sz-cs w:val=\"18\"/>
                            </w:rPr>
                            <w:fldChar w:fldCharType=\"begin\">
                                <w:fldData xml:space=\"preserve\">/////2UAAAAUABIASwBvAG4AdAByAG8AbABsAGsA5ABzAHQAYwBoAGUAbgAyADMAAAAAAAAAAAAA\r\nAAAAAAAAAAAAAAAAAAAA\r\n</w:fldData>
                            </w:fldChar>
                        </w:r>
                        <w:r wsp:rsidRPr=\"00A81C11\">
                            <w:rPr>
                                <w:rFonts w:ascii=\"Arial\" w:h-ansi=\"Arial\"/>
                                <wx:font wx:val=\"Arial\"/>
                                <w:b/>
                                <w:sz w:val=\"18\"/>
                                <w:sz-cs w:val=\"18\"/>
                            </w:rPr>
                            <w:instrText> FORMCHECKBOX </w:instrText>
                        </w:r>
                        <w:r wsp:rsidRPr=\"00A81C11\">
                            <w:rPr>
                                <w:rFonts w:ascii=\"Arial\" w:h-ansi=\"Arial\"/>
                                <wx:font wx:val=\"Arial\"/>
                                <w:b/>
                                <w:sz w:val=\"18\"/>
                                <w:sz-cs w:val=\"18\"/>
                            </w:rPr>
                        </w:r>
                        <w:r wsp:rsidRPr=\"00A81C11\">
                            <w:rPr>
                                <w:rFonts w:ascii=\"Arial\" w:h-ansi=\"Arial\"/>
                                <wx:font wx:val=\"Arial\"/>
                                <w:b/>
                                <w:sz w:val=\"18\"/>
                                <w:sz-cs w:val=\"18\"/>
                            </w:rPr>
                            <w:fldChar w:fldCharType=\"end\"/>
                        </w:r>
                    </w:p>

My C# code where I am extracting this XML:

Microsoft.Office.Interop.Word._Application word = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(Path);
        XML_FROM_DOC = doc.Content.XML;
        doc.Close();
        word.Quit();

Any suggestions please? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire