【问题标题】:generating jasper reports using ireport designer tool使用 ireport 设计器工具生成 jasper 报告
【发布时间】:2014-07-09 17:36:24
【问题描述】:

我使用 ireport 设计器工具生成了 PDF 报告。到这里还好。

我的问题是:

如果数据库中没有数据,则显示空白 pdf 页面。此时如何在 pdf 中显示“未找到此请求的数据”?

【问题讨论】:

  • 您是否在报告中使用参数或字段?
  • 向我们展示您为打印可用数据所做的代码..
  • 我正在使用参数
  • 文件 reportFile = new File(application.getRealPath("report.jasper"));Map 参数 = new HashMap(); parameters.put("faculty_createdby", loginUtil.getUser_name()); byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, con); response.setContentType("应用程序/pdf"); response.setContentLength(bytes.length); ServletOutputStream outStream = response.getOutputStream(); outStream.write(bytes, 0, bytes.length);

标签: java jasper-reports


【解决方案1】:

模板有一个属性WhenNoDataType。

只需将其设置为WhenNoDataType: AllSectionsNoDetail。

这将有模板(静态字段)但没有来自数据库的动态数据。

如果您只想打印一些信息,则必须稍微更改设计。您需要在报告的开头放置一个条件,以检查数据是否来自数据库,并采取相应措施。

【讨论】:

  • 无需在您的报告中添加条件。如果您使用 noData 部分,Jasper 会自动执行此操作。
  • 是的,但是如果有人只想在没有来自数据库的数据时才显示消息怎么办?你将如何做到这一点?
  • 这正是noData 部分的作用。如果查询成功但结果集包含 0 行,则显示 noData 部分(并且仅显示该部分)。
  • 你能给我一些工作链接吗?不使用数据部分。
  • 如果你看一下我的回答,你会看到我包含了一个我在 iReport 5.0.0 中创建的工作示例。乐队的解释在第109页:jasperreports.sourceforge.net/…
【解决方案2】:

如果您不想在没有数据(没有标题、页眉、页脚等)的情况下不显示报告的任何内容,那么您应该在报告中添加noData 带区并将消息放在那里。然后将whenNoDataType报告参数改为NoDataSection

来自 JasperReports 终极指南

如果在报告模板中定义了<noData> 部分,并且数据源为空,则在填充时将只考虑<noData> 部分

例子:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
        name="report1" 
        whenNoDataType="NoDataSection">

    <pageHeader>
        <band height="20">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20"/>
                <text><![CDATA[Page Header]]></text>
            </staticText>
        </band>
    </pageHeader>
    <detail>
        <band height="20">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20"/>
                <text><![CDATA[Detail]]></text>
            </staticText>
        </band>
    </detail>
    <pageFooter>
        <band height="20">
            <staticText>
                <reportElement x="0" y="0" width="100" height="20"/>
                <text><![CDATA[Page Footer]]></text>
            </staticText>
        </band>
    </pageFooter>
    <noData>
        <band height="20">
            <staticText>
                <reportElement x="0" y="0" width="555" height="20"/>
                <text><![CDATA[No data found for this request]]></text>
            </staticText>
        </band>
    </noData>
</jasperReport>

【讨论】:

  • 非常感谢 GenericJon 先生
  • 先生。乔恩,我对 3D 条形图有一些疑问,1. 如果它是数据库中的单条记录,那么条形图在条形图中显示全宽。我们如何设置宽度?如果有更多的记录,那么它将自动拉伸。 2. 如何在 Y 轴上只显示数字,在 Y 轴上只显示垂直标题
  • @Surendra 您应该针对这些问题提出新问题。
猜你喜欢
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-26
  • 2015-05-01
  • 1970-01-01
相关资源
最近更新 更多