简体   繁体   中英

How to manipulate OptionButton / Radio button on docx with Open XML? (C#)

I have a.docx template that I need to fill with C#. This template has some sections with radio button groups, just like this:

在此处输入图像描述

I'm using open XML, I've inspected the xml and I think I found the radio buttons:

          <w:p w14:paraId="6E7C5D2C" w14:textId="2740F2E7" w:rsidR="0085589C" w:rsidRPr="00055073" w:rsidRDefault="0085589C" w:rsidP="00465D62">
              <w:r>
                 <w:object w:dxaOrig="225" w:dyaOrig="225" w14:anchorId="28DEEE36">
                    <v:shape id="_x0000_i1053" type="#_x0000_t75" style="width:78pt;height:17.25pt" o:ole="">
                       <v:imagedata r:id="rId15" o:title="" />
                    </v:shape>
                    <w:control r:id="rId16" w:name="OptionButton3" w:shapeid="_x0000_i1053" />
                 </w:object>
              </w:r>
           </w:p>

I can't figure out how to manipulate these elements with C#. I tried to iterate through doc elements and found an element with name OptionButton of type Control, but I haven't found a property or method that allows me to manipulate its value:

在此处输入图像描述

Could someone help me with this, please?

Thank you.

The Option Buttons shown in the question are ActiveX controls, originally designed to be used in VBA UserForms. Office document surfaces were then adapted to allow them to be used in documents, retaining their programming interface.

ActiveX controls are not defined by Office Open XML. As with all things VBA, they remain in the proprietary binary format (pre-Office 2007).

Here's an extract of the Word Open XML for an Option button:

<pkg:part pkg:name="/word/activeX/activeX1.bin" pkg:contentType="application/vnd.ms-office.activeX">
<pkg:binaryData>0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAA
EAAAAgAAAAEAAAD+////AAAAAAAAAAD/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////

In order to "read" this kind of content it would be necessary to have access to and understand the Word and Office binary file formats.

Reference, for example: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-doc/ccd7b486-7881-484c-a137-51170af7cc22

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM