首页 \ 问答 \ 如何从子报表返回值以隐藏空带?(How to return values from subreport to hide empty bands?)

如何从子报表返回值以隐藏空带?(How to return values from subreport to hide empty bands?)

我有几个子报告,所有这些子报告都包含在不同的带中。

例如:

...
<detail>
    <band height="500">
            <subreport>
                <reportElement isPrintRepeatedValues="false" x="-10" y="0" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentASubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentASubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-1"/>
            </break>
    </band> 
    <band height="500"> 
            <subreport> 
                <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentBSubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentBSubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-2"/>
            </break>
    </band>
    <band height="500"> 
            <subreport> 
                <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentCSubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentCSubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-3"/>
            </break>
    </band>
    ...
... 

如果子报表不包含元素,我想隐藏元素band

我将变量SUB_REPORT_ROW_CNT添加到子报表并将其链接到变量REPORT_COUNT ,该变量包含报表中的行数(在本例中为子报表)。

<variable name="SUB_REPORT_ROW_CNT" class="java.lang.Integer" resetType="Report" calculation="Nothing">
    <variableExpression><![CDATA[$V{REPORT_COUNT}]]></variableExpression>
</variable>

在主报告的每个频段中,我添加了以下内容:

<band height="500"> 
        <printWhenExpression><![CDATA[$V{SUB_REPORT_ROW_CNT} != 0]]></printWhenExpression>          
        <subreport> 
            <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                <dataSourceExpression><![CDATA[$P{DepartmentASubReportData}]]></dataSourceExpression>
                <returnValue subreportVariable="SUB_REPORT_ROW_CNT" toVariable="SUB_REPORT_ROW_CNT"/>
                <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                <![CDATA[$P{DepartmentASubReport}]]></subreportExpression>
        </subreport>
        <break type="Page">
            <reportElement x="-10" y="1" width="325" height="1" key="element-2"/>
        </break>
</band>

但表达式$V{SUB_REPORT_ROW_CNT} != 0始终被评估为false

如果我通过使用下一个块打印变量的值,我总是得到一个null

<textField>
    <reportElement x="8" y="40" width="540" height="18"  />
    <textElement textAlignment="Center" verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[$V{SUB_REPORT_ROW_CNT}]]></textFieldExpression>
</textField>

可能是什么错误?..如何从子报表返回值来隐藏空带?

我非常感谢这些信息。 谢谢大家。


I have several subreports and all of these subreports are contained in separate bands.

For example:

...
<detail>
    <band height="500">
            <subreport>
                <reportElement isPrintRepeatedValues="false" x="-10" y="0" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentASubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentASubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-1"/>
            </break>
    </band> 
    <band height="500"> 
            <subreport> 
                <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentBSubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentBSubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-2"/>
            </break>
    </band>
    <band height="500"> 
            <subreport> 
                <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                    <dataSourceExpression><![CDATA[$P{DepartmentCSubReportData}]]></dataSourceExpression>
                    <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                    <![CDATA[$P{DepartmentCSubReport}]]></subreportExpression>
            </subreport>
            <break type="Page">
                <reportElement x="-10" y="1" width="325" height="1" key="element-3"/>
            </break>
    </band>
    ...
... 

If the subreport doesn't contains elements, I would like to hide the element band.

I added the variable SUB_REPORT_ROW_CNT to the subreport and linked it to the variable REPORT_COUNT, which contains the number of rows in the report (in the subreport in this case).

<variable name="SUB_REPORT_ROW_CNT" class="java.lang.Integer" resetType="Report" calculation="Nothing">
    <variableExpression><![CDATA[$V{REPORT_COUNT}]]></variableExpression>
</variable>

In every band of the master report I added the following:

<band height="500"> 
        <printWhenExpression><![CDATA[$V{SUB_REPORT_ROW_CNT} != 0]]></printWhenExpression>          
        <subreport> 
            <reportElement isPrintRepeatedValues="false" x="-10" y="1" width="325" height="1" isRemoveLineWhenBlank="true" backcolor="#ffcc99"/>
                <dataSourceExpression><![CDATA[$P{DepartmentASubReportData}]]></dataSourceExpression>
                <returnValue subreportVariable="SUB_REPORT_ROW_CNT" toVariable="SUB_REPORT_ROW_CNT"/>
                <subreportExpression class="net.sf.jasperreports.engine.JasperReport">
                                <![CDATA[$P{DepartmentASubReport}]]></subreportExpression>
        </subreport>
        <break type="Page">
            <reportElement x="-10" y="1" width="325" height="1" key="element-2"/>
        </break>
</band>

But the expression $V{SUB_REPORT_ROW_CNT} != 0 is always evaluated as false.

And if I print the value of a variable by using the next block, I always get a null.

<textField>
    <reportElement x="8" y="40" width="540" height="18"  />
    <textElement textAlignment="Center" verticalAlignment="Middle"/>
    <textFieldExpression><![CDATA[$V{SUB_REPORT_ROW_CNT}]]></textFieldExpression>
</textField>

What could be the error?.. How to return values from subreport to hide empty bands?..

I would be very grateful for the information. Thanks to all.


原文:https://stackoverflow.com/questions/45943329
更新时间:2022-05-23 12:05

最满意答案

为什么在这里使用正则表达式? 我没有看到好处。 你可以做的是对输入字符串进行排序(例如,'sak'和'ask'将变成'aks'),并将该排序后的字符串与参考字符串'aks'进行比较。 或者只是在引用字符串'ask'上使用相同的函数。 像这样的东西:

function str_sort($str) {
    $chars = str_split($str);
    sort($chars);
    return implode('', $chars);
}

$pattern = 'ask';
$input = 'sak';
$valid = str_sort($pattern) == str_sort($input);

echo "Pattern: $pattern;\n";
echo "Input  : $input\n";
echo "Valid  : " . ($valid ? 'yes' : 'no') . "\n";

Why using a regex here? I don't see the benefit. What you could do is sort the input string (e.g. both 'sak' and 'ask' will turn into 'aks') and compare that sorted string to a reference string, 'aks' in this case. Or just use the same function on the reference string 'ask' as well. Something like this:

function str_sort($str) {
    $chars = str_split($str);
    sort($chars);
    return implode('', $chars);
}

$pattern = 'ask';
$input = 'sak';
$valid = str_sort($pattern) == str_sort($input);

echo "Pattern: $pattern;\n";
echo "Input  : $input\n";
echo "Valid  : " . ($valid ? 'yes' : 'no') . "\n";

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)