How to access Report Name attribute from within a report?

后端 未结 2 959
粉色の甜心
粉色の甜心 2021-01-27 11:53

In a jasper report, with iReports Designer one can set the Report Name to some value (in iReports, this is on the most top node in the report inspector).

How can the val

相关标签:
2条回答
  • 2021-01-27 12:25

    The answer from Alex K is correct. I just want to add additional information on how to do this in Jasper Scriplets as it might help people finding this answer:

    String nameOfReport = ((JasperReport)getParameterValue(JRFillParameter.JASPER_REPORT)).getName(); // Name of report
    String fullReportUnitPath = ((JasperReport)getParameterValue(JRFillParameter.JASPER_REPORT)).getProperty("ireport.jasperserver.reportUnit"); // path to report unit
    
    // for getting the folder name above the report file a.k.a reportunit
    int indexOfLastPathSlash = fullReportUnitPath.lastIndexOf("/");
    String nameOfReportUnit =  fullReportUnitPath.substring(indexOfLastPathSlash+1);
    
    0 讨论(0)
  • 2021-01-27 12:32

    With help of JASPER_REPORT parameter we can get instance of JasperReport class. This is the current template object.

    With help of JasperReport.getName() method we can get the report name.

    Example of template

    <?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="Show the report name example" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
        <title>
            <band height="50" splitType="Stretch">
                <textField>
                    <reportElement x="110" y="0" width="290" height="25"/>
                    <textFieldExpression><![CDATA[$P{JASPER_REPORT}.getName()]]></textFieldExpression>
                </textField>
            </band>
        </title>
    </jasperReport>
    

    In this example the name of report is: name="Show the report name example"

    The output result in Studio

    0 讨论(0)
提交回复
热议问题