2

我无法在jrxml的表格中显示复选框。

这是我的代码示例:

<detail>
    <band height="45" splitType="Stretch">
        <textField isBlankWhenNull="true">
            <reportElement style="MyCustomStyle" stretchType="RelativeToTallestObject" x="650" y="0" width="80" height="35"/>
            <textElement textAlignment="Center"/>
            <textFieldExpression class="java.lang.Boolean"><![CDATA[$F{myBooleanVariable}]]>
            </textFieldExpression>
        </textField>
    </band>
</detail>

该列仅显示truefalse。我认为class="java.lang.Boolean"textFieldExpression元素中指定会将值转换为复选框,但显然,我需要的还不止这些。

知道我做错了什么吗?

4

5 回答 5

6

我刚刚在您已经制作的解决方案中添加了一些 unicode:

<textFieldExpression><![CDATA[$F{myBooleanVairiable}? "\u2713":"\u2717"]]></textFieldExpression>

u2713转换为刻度线和u2717十字

请记住确保将 xml 页面顶部的编码语句设置为 UTF8:

于 2013-08-06T15:19:06.987 回答
4

jasper HTML报告中的复选框可以如下

<textFieldExpression><![CDATA[$F{myBooleanVairiable}? "\u2713":"\u2717"]]></textFieldExpression>

注意:必须使用支持unicode的字体

在 PDF 中不能使用上面的代码。我们必须使用字体扩展名或通过如下方式绘制线条

<frame>
<reportElement x="161" y="73" width="12" height="12"/>
<box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
    <pen lineWidth="1.0"/>
    <topPen lineWidth="1.0"/>
    <leftPen lineWidth="1.0"/>
    <bottomPen lineWidth="1.0"/>
    <rightPen lineWidth="1.0"/>
</box>
<line>
    <reportElement x="2" y="7" width="2" height="2">
        <printWhenExpression><![CDATA[Boolean Exprssion]></printWhenExpression>
    </reportElement>
</line>
<line direction="BottomUp">
    <reportElement x="4" y="3" width="6" height="6">
        <printWhenExpression><![CDATA[Boolean Exprssion]]]></printWhenExpression>
    </reportElement>
</line>

于 2015-07-28T10:58:42.990 回答
4

很简单,在标签 ->imageExpression<- 上执行此操作

        <componentElement>
            <reportElement x="196" y="109" width="46" height="39"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset3">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{fisicos})]]></dataSourceExpression>
                </datasetRun>
                <jr:listContents height="39" width="46">
                    <image>
                        <reportElement x="12" y="0" width="17" height="21"/>
                        <imageExpression><![CDATA[$F{_THIS} == true ? $P{checkboxFisicoOK} : $P{checkboxFisicoNOK}]]></imageExpression>
                    </image>
                </jr:listContents>
            </jr:list>
        </componentElement>

在此处输入图像描述

  • checkboxFisicoOK:是图片路径的参数。

    <parameter name="checkboxFisicoOK" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[new java.lang.String("/Users/ccamol/onprocess/checkboxOK.jpg")]]></defaultValueExpression>
    </parameter>
    
于 2016-07-19T21:24:52.277 回答
2

好吧,显然不可能在使用该语言的表格中添加复选框!

所以现在我只显示是/否:

<textFieldExpression class="java.lang.String"><![CDATA[$F{myBooleanVariable}?"YES":"NO"]]></textFieldExpression>

这是我能找到的最好的!

于 2011-06-21T12:45:50.470 回答
1

对于 PDF 这对我有用,明确地将字体设置为支持 unicode 的字体:

<textField>
    <textElement>
        <font fontName="DejaVu Sans" size="16"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{myBooleanVariable}?"\u2611" : "\u2610"]]></textFieldExpression>
</textField>
于 2019-07-25T09:17:43.237 回答