PHPJasperXML无法在php

时间:2018-09-22 09:15:43

标签: php jasper-reports web-deployment

我正在使用PHPJasperXML生成和显示报告

首先,我使用jaspersoft Studio设计报告

第二,我使用php中jasper生成的jrxml文件来显示报告。

当我在jasper studio中预览报表时,一切都按预期运行,但是问题是当我尝试显示php报表时,该报表仅与主报表中的数据一起生成,该表的数据为没有产生。

当我从jaspersoft studio预览报告时,得到了预期的结果 enter image description here

但是当我尝试从PHP运行相同的报告时:

enter image description here

它向我显示了一个没有表格数据的列表。

在jaspersoft studio中用于设计报告的代码

    <?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0  -->
<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="eleve_admis" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="466e7fc7-2c42-45cc-9626-1e50658cbee4">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <style name="Table_TH" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#828282"/>
            <topPen lineWidth="0.5" lineColor="#828282"/>
            <leftPen lineWidth="0.5" lineColor="#828282"/>
            <bottomPen lineWidth="0.5" lineColor="#828282"/>
            <rightPen lineWidth="0.5" lineColor="#828282"/>
        </box>
    </style>
    <style name="Table_CH" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#828282"/>
            <topPen lineWidth="0.5" lineColor="#828282"/>
            <leftPen lineWidth="0.5" lineColor="#828282"/>
            <bottomPen lineWidth="0.5" lineColor="#828282"/>
            <rightPen lineWidth="0.5" lineColor="#828282"/>
        </box>
    </style>
    <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#828282"/>
            <topPen lineWidth="0.5" lineColor="#828282"/>
            <leftPen lineWidth="0.5" lineColor="#828282"/>
            <bottomPen lineWidth="0.5" lineColor="#828282"/>
            <rightPen lineWidth="0.5" lineColor="#828282"/>
        </box>
    </style>
    <subDataset name="eleve_admis_dataset" uuid="3df422c8-c3c8-4109-ba68-e0d8d87701b2">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
        <parameter name="class_id_table" class="java.lang.String"/>
        <queryString language="SQL">
            <![CDATA[SELECT CONCAT(' ',student_lastname, ' ', ' ' , student_middlename, ' ', student_firstname) as Fullname, DATE_FORMAT(student_date_of_birth, "%d/%c/%Y") as dob, student_sex, 
IF(student_sex = "Femme", "F", "M") as sex
FROM student as S, student_class as C
 WHERE S.stu_class = C.class_id AND C.class_id = "$P{class_id_table}"]]>
        </queryString>
        <field name="Fullname" class="java.lang.String">
            <property name="com.jaspersoft.studio.field.label" value="Fullname"/>
        </field>
        <field name="dob" class="java.lang.String">
            <property name="com.jaspersoft.studio.field.label" value="dob"/>
        </field>
        <field name="student_sex" class="java.lang.String">
            <property name="com.jaspersoft.studio.field.label" value="student_sex"/>
            <property name="com.jaspersoft.studio.field.tree.path" value="student"/>
        </field>
        <field name="sex" class="java.lang.String">
            <property name="com.jaspersoft.studio.field.label" value="sex"/>
        </field>
    </subDataset>
    <parameter name="class_id" class="java.lang.String"/>
    <queryString language="SQL">
        <![CDATA[select CONCAT("Lisf For", '  ', class_no, '  ',class_description ) as classe, CONCAT("DATE:  ", DATE_FORMAT(CURDATE(), "%d/%c/%Y")) as date
FROM student_class
WHERE class_id = "$P{class_id}"]]>
    </queryString>
    <field name="classe" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="classe"/>
    </field>
    <field name="date" class="java.lang.String">
        <property name="com.jaspersoft.studio.field.label" value="date"/>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="98" splitType="Stretch">
            <textField>
                <reportElement x="14" y="50" width="535" height="40" uuid="4e2a3adb-6a43-4b28-8669-17c9f81a6486"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="15" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{classe}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="360" y="0" width="190" height="30" uuid="ba6e5b18-4b85-4e4d-be68-338316e2b427"/>
                <textElement textAlignment="Right" verticalAlignment="Middle">
                    <font size="12" isBold="true"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
            </textField>
        </band>
    </title>
    <detail>
        <band height="213" splitType="Stretch">
            <componentElement>
                <reportElement x="90" y="10" width="383" height="80" uuid="a4ea31f7-b6a9-4be7-b304-72afa82cba5f">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="eleve_admis_dataset" uuid="07815e66-5865-4839-ad1d-27cade45b0eb">
                        <datasetParameter name="class_id_table">
                            <datasetParameterExpression><![CDATA[$P{class_id}]]></datasetParameterExpression>
                        </datasetParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="200" uuid="77d235be-53cc-4ba2-9f46-6f40cc3c38dd">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="200" height="30" uuid="a7dbdc1d-52be-49f4-a402-bb0afcb02aa2"/>
                                <textElement textAlignment="Left" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[  Nom ]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="50">
                            <textField>
                                <reportElement x="0" y="0" width="200" height="50" uuid="30821ecb-5df5-43a3-8ca7-13563d10487a"/>
                                <textElement textAlignment="Left" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="14"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{Fullname}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" uuid="5caeec2a-89eb-4a8f-9ac0-6f87897919fd">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="90" height="30" uuid="789641df-5783-471b-a757-128097c085ab"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[ Age]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="50">
                            <textField>
                                <reportElement x="0" y="0" width="90" height="50" uuid="2d2780b8-8120-4b16-872a-60134a5144f5"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="14"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{dob}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="93" uuid="3f04649c-337e-4da6-a915-f010d97d093f">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                        <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="93" height="30" uuid="78655fb0-fe8a-4f0b-866e-239b0392f7b3"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[  Sexe]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="50">
                            <textField>
                                <reportElement x="0" y="0" width="93" height="50" uuid="8550aef2-10d9-408c-9b17-6684eb7bf77d"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font fontName="trebuchet&#xD;&#xA;" size="14"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{sex}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

用于显示报告的PHP代码为:

<?php 

     require_once("../private/initialize.php");
     include_once('phpjasperxml_0.9d/class/tcpdf/tcpdf.php');
     include_once("phpjasperxml_0.9d/class/PHPJasperXML.inc.php"); // PHPJasperXML

     error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

     $class_id = (int)$_GET['class'];

     $params = array();
     $params['class_id'] = $class_id; 
     $params['class_id_table'] = $class_id;

     $PHPJasperXML = new PHPJasperXML();
     //$PHPJasperXML->debugsql=true;
     $PHPJasperXML->arrayParameter =  $params;
     $PHPJasperXML->load_xml_file("reports/eleve_admis.jrxml"); // Name of the reports file
     $PHPJasperXML->transferDBtoArray($servername,$username, $password, $database);
     $PHPJasperXML->outpage("I"); 

?>

对于此问题的任何帮助,我将不胜感激。 或其他建议,建议其他开放源代码库使用PHP生成报告

1 个答案:

答案 0 :(得分:0)

如果您使用php 7,它将无法正常工作。 mysql_connect在PHP 5.5.0中不推荐使用该扩展,在PHP 7.0.0中将其删除。 有关更多信息,请访问http://php.net/manual/en/function.mysql-query.php