如何从子报表返回值以隐藏空带?(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 variableREPORT_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 asfalse
.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
最满意答案
为什么在这里使用正则表达式? 我没有看到好处。 你可以做的是对输入字符串进行排序(例如,'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";
相关问答
更多-
免责声明:以下是非常幼稚的方法,既不快捷也不美观。 然而,它为简单的正则表达式完成了工作。 如果不理解它的作用,我不建议使用它 #include
#include #include bool is_valid_regex_string(const std::string& rgx_str) { bool bResult = true; try { std::regex tmp(rgx_str); } ... -
检查一个字符串是否匹配一个正则表达式或不是红宝石的最快方法?(Fastest way to check if a string matches a regexp or not in ruby?)[2023-07-18]
从Ruby 2.4.0开始,您可以使用RegExp#match? : pattern.match?(string) Regexp#match? 在2.4.0的发行说明中被明确列为性能增强,因为它避免了其他方法执行的对象分配,如Regexp#match和=~ : 正则表达式匹配#? 添加了Regexp#match? ,它执行正则表达式匹配,而不创建反向引用对象,并更改$~以减少对象分配。 Starting with Ruby 2.4.0, you may use RegExp#match?: pattern ... -
使用regex.test()如果你想要的是一个布尔结果: /^([a-z0-9]{5,})$/.test('abc1'); // false /^([a-z0-9]{5,})$/.test('abc12'); // true /^([a-z0-9]{5,})$/.test('abc123'); // true ...你可以从你的正则表达式中删除() ,因为你不需要捕获。 Use regex.test() if all you want is a boolean result: /^([a- ...
-
得到它全部排序。 干杯 def get_token(self): '''Returns the next token and the part of input_string it matched. The returned token is None if there is no next token. The characters up to the end of the token are consumed. Raise an exception by ...
-
试试吧 var filteredMatches = arr.filter(function(val){ return val.indexOf("XX") == 0; }); simply try var filteredMatches = arr.filter(function(val){ return val.indexOf("XX") == 0; });
-
PHP正则表达式检查字符串(PHP regex to check a string)[2024-02-09]
^[A-Z][0-9]{3}$ 说明: ^ # start of string [A-Z] # one character, A-Z [0-9]{3} # three characters, 0-9 $ # end of string ^[A-Z][0-9]{3}$ Explanation: ^ # start of string [A-Z] # one character, A-Z [0-9]{3} # three characte ... -
为什么在这里使用正则表达式? 我没有看到好处。 你可以做的是对输入字符串进行排序(例如,'sak'和'ask'将变成'aks'),并将该排序后的字符串与参考字符串'aks'进行比较。 或者只是在引用字符串'ask'上使用相同的函数。 像这样的东西: function str_sort($str) { $chars = str_split($str); sort($chars); return implode('', $chars); } $pattern = 'ask'; $inp ...
-
注意:此答案假定a和b是单词,即仅包含字符[a-zA-Z0-9_] 。 如果这不是您想要的,请在下面的示例中适当地替换\w+ 。 if\s+(\w+)\s*&\s*(\w+) 匹配以下内容: if a & b if foo&bar 细分: 匹配单词if 寻找至少一个空白字符 匹配(并捕获)一个单词 匹配0个或更多的空格字符 匹配&字符 匹配0个或更多的空格字符 匹配(并捕获)一个单词 Note: This answer assumes that a and b are words, that is, o ...
-
有没有办法检查两个正则表达式是否可以匹配相同的字符串?(Is there a way to check if two regexps can match the same string? [duplicate])[2021-12-28]
这取决于。 对于perl兼容的正则表达式(pcre),这通常是不可能的,因为它们是完整的:你甚至不能确定匹配总是终止。 对于Chomsky层次结构中定义的原始的“干净”形式的调节器语言,已知它们在交叉点下是封闭的,这已在本线程中讨论过。 只要交叉点有NFA ,就可以很容易地检查是否有任何字符串匹配 - 如果thera是从NFA的开头到结尾的路径,那么此路径的字符串就是您要搜索的字符串对于DFA, 这里给出了一种算法,它应该很容易适应NFA。 It depends. For perl compatible r ... -
在正则表达式的两端添加锚点 ,加上量词(如果要排除空字符串,则为+ ;如果要允许空字符串,则为* )。 现在,你只是检查第一个字符(单数)是否是字母(即匹配[a-zA-Z] )。 你想要的是: re.match("^[a-zA-Z]+$", textToRestrict) (或者,如果您的过滤器真的很简单,请考虑使用像str.isalpha这样的字符串方法, 正如SirParselot在评论中所建议的那样 。) Add anchors at both ends of the regex, plus a q ...