在MS Word文档中使用docx4j设置/取消复选框值 [英] set/unset checkbox value with docx4j in MS Word document

查看:243
本文介绍了在MS Word文档中使用docx4j设置/取消复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MS Word文档中的 docx4j 设置/取消复选框的值.

I'm trying to set/unset checkbox value with docx4j in MS Word document.

使用本文中的代码: docx4j选中复选框我收到了以下XML我文档中的元素:

Using code from this post: docx4j checking checkboxes I received following XML of this element from my document:

<w:fldChar w:fldCharType="begin" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:ns21="urn:schemas-microsoft-com:office:powerpoint" xmlns:ns23="http://schemas.microsoft.com/office/2006/coverPageProps" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:odx="http://opendope.org/xpaths" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:ns17="urn:schemas-microsoft-com:office:excel" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:odi="http://opendope.org/components" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:ns9="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ns32="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:ns30="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:ns12="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:ns31="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:odq="http://opendope.org/questions" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:odc="http://opendope.org/conditions" xmlns:oda="http://opendope.org/answers">
<w:ffData>
    <w:name w:val=""/>
    <w:enabled/>
    <w:calcOnExit w:val="false"/>
    <w:checkBox>
        <w:sizeAuto/>
        <w:default w:val="true"/>
    </w:checkBox>
</w:ffData>

如何取消设置此复选框的值?

How could I unset value of this checkbox?

谢谢!

推荐答案

您需要找到您的复选框元素,剩下的就变得微不足道了.例子.

You need to find your check box element, and when you have it the rest is trivial. Example.

for (Object o2 : contentControl.getSdtPr().getRPrOrAliasOrLock()) {

        o2 = XmlUtils.unwrap(o2);
        if (o2 instanceof CTSdtCheckbox) {

            CTSdtCheckbox cTSdtCheckbox = (CTSdtCheckbox) o2;
            CTOnOff ctOnOff = new CTOnOff();

            ctOnOff.setVal("1!);
            cTSdtCheckbox.setChecked(ctOnOff);
        }

}

这篇关于在MS Word文档中使用docx4j设置/取消复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆