简体   繁体   English

如何使用 Open XML 操作 docx 上的 OptionButton / Radio 按钮? (C#)

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

I have a.docx template that I need to fill with C#.我有一个需要用 C# 填充的 .docx 模板。 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:我正在使用打开的 XML,我检查了 xml,我想我找到了单选按钮:

          <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#.我不知道如何用 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:我试图遍历 doc 元素并找到一个名为 OptionButton 类型为 Control 的元素,但我还没有找到允许我操纵其值的属性或方法:

在此处输入图像描述

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.问题中显示的选项按钮是ActiveX控件,最初设计用于 VBA 用户窗体。 Office document surfaces were then adapted to allow them to be used in documents, retaining their programming interface.然后对 Office 文档表面进行了调整,以允许它们在文档中使用,同时保留其编程接口。

ActiveX controls are not defined by Office Open XML. ActiveX 控件不是由 Office Open XML 定义的。 As with all things VBA, they remain in the proprietary binary format (pre-Office 2007).与 VBA 的所有内容一样,它们仍采用专有的二进制格式(Office 2007 之前)。

Here's an extract of the Word Open XML for an Option button:以下是选项按钮的 Word Open XML 的摘录:

<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.为了“阅读”此类内容,有必要访问并理解 Word 和 Office 二进制文件格式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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