数据库表中的标题和详细信息

发布于 2024-12-26 03:03:54 字数 279 浏览 2 评论 0原文

我需要一个编辑器来创建一些报告,所有报告都有标题(公司名称、地址、电话、图像),该标题是从名为公司的表中读取的,并有该公司所有客户的详细示例。

我怎样才能在 iReports 中做到这一点?

有什么方法可以链接我的报告中的两个表(公司和客户)?因为“报表查询”只允许我一句话。

我使用 Java Swing 和 MySql 数据库。

感谢您的有用评论。

报告示例

I need an editor to create some reports, all reports have header (company name, address, phone, image) that is read from a table called companies and have a detailed, example all customers of the company.

How could I do this in iReports?

Is there any way to link two tables (company and customer) in my report? because the "report query" only allows me a sentence.

I work with Java Swing and MySql database.

Thanks for your helpful comments.

Report example

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的轨迹 2025-01-02 03:03:54

我需要一个编辑器来创建一些报告,所有报告都有标题(公司名称、地址、电话、图像),该标题是从名为公司的表中读取的,并有该公司所有客户的详细示例。我怎样才能在 iReports 中做到这一点?

您可以查看此示例JasperReports 分发包 包含许多其他示例(在文件夹中) %jasperreports%\demo\samples)。 iReport 文件夹 %iReport%\ireport\samples 中还有多个示例。

您的样本报告非常简单。

创建此类报告的步骤可以如下所示:

  1. image 元素(带有公司徽标)和多个(或一个)staticText 元素(带有公司联系信息)添加到标题带。
  2. 添加带有字段(示例中的 idClientnameaddress)的查询(用于从 MySQL DB 获取数据)
  3. 将带有列标题的 staticText 元素添加到 Column header 带 - 它将成为数据网格的列标题
  4. 将带有字段的 textField 元素添加到 em>Detail 带 - 它将是网格中的数据

您应该阅读JasperReports 终极指南。这是一个很棒的教程。

示例jrxml文件(在iReport中设计):

<?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="sample_company" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString>
        <![CDATA[SELECT idClient, name, address FROM customers_table]]>
    </queryString>
    <field name="idClient" class="java.lang.Integer"/>
    <field name="name" class="java.lang.String"/>
    <field name="address" class="java.lang.String"/>
    <title>
        <band height="108" splitType="Stretch">
            <staticText>
                <reportElement x="171" y="53" width="183" height="55"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
                <text><![CDATA[<style isBold="true" forecolor="blue">ABC COMPANY</style>
Main Avenue and 9th Street
Tel: (593)  4 - 2066765
e-mail: [email protected]]]></text>
            </staticText>
            <image>
                <reportElement x="245" y="3" width="41" height="50"/>
                <imageExpression><![CDATA["abc_logo.png"]]></imageExpression>
            </image>
        </band>
    </title>
    <columnHeader>
        <band height="20">
            <staticText>
                <reportElement x="11" y="0" width="160" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Id Client]]></text>
            </staticText>
            <staticText>
                <reportElement x="171" y="0" width="183" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="354" y="0" width="172" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Address]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="11" y="0" width="160" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{idClient}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="354" y="0" width="172" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="171" y="0" width="183" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

结果将是(导出为pdf格式的报告):

PDF 格式的报告

更新:

要使用公司信息填充标题,您可以使用 < em>组乐队。您可以在此处阅读有关群组的信息。

您的查询将如下所示:

SELECT c.idClient, c.name, c.address, cmp.name AS companyName, cmp.contactInfo, cmp.id AS idCompany FROM customers c, companies cmp WHERE cmp.id=c.idCompany SORT BY cmp.id

您还应该为 companies 表 (companies.name<例如 /code>companies.contactInfocompanies.id):

    <field name="companyName" class="java.lang.String"/>
    <field name="contactInfo" class="java.lang.String"/>
    <field name="idCompany" class="java.lang.String"/>

之后您应该添加 idCompanycompanies 表中的唯一键)。
然后将带有字段(companyNamecontactInfo)的 textField 元素放入乐队。

I need an editor to create some reports, all reports have header (company name, address, phone, image) that is read from a table called companies and have a detailed, example all customers of the company. How could i do this in iReports?

You can look at this samples. The JasperReports distribution package contains many others samples (in folder %jasperreports%\demo\samples). The iReport has also several samples in folder %iReport%\ireport\samples.

Your sample report is very simple.

The steps for creating the such report can be like this:

  1. Adding image element (with company logo) and several (or one) staticText elements (with company contact information) to the Title band.
  2. Adding query (for getting data from MySQL DB) with fields (idClient, name, address in your sample)
  3. Adding staticText elements with columns header to the Column header band - it will be the columns header for data grid
  4. Adding textField elements with fields to the Detail band - it will be the data in grid

You should read the JasperReports Ultimate Guide. It is a great tutorial.

The sample jrxml file (designed in iReport):

<?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="sample_company" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <queryString>
        <![CDATA[SELECT idClient, name, address FROM customers_table]]>
    </queryString>
    <field name="idClient" class="java.lang.Integer"/>
    <field name="name" class="java.lang.String"/>
    <field name="address" class="java.lang.String"/>
    <title>
        <band height="108" splitType="Stretch">
            <staticText>
                <reportElement x="171" y="53" width="183" height="55"/>
                <textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/>
                <text><![CDATA[<style isBold="true" forecolor="blue">ABC COMPANY</style>
Main Avenue and 9th Street
Tel: (593)  4 - 2066765
e-mail: [email protected]]]></text>
            </staticText>
            <image>
                <reportElement x="245" y="3" width="41" height="50"/>
                <imageExpression><![CDATA["abc_logo.png"]]></imageExpression>
            </image>
        </band>
    </title>
    <columnHeader>
        <band height="20">
            <staticText>
                <reportElement x="11" y="0" width="160" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Id Client]]></text>
            </staticText>
            <staticText>
                <reportElement x="171" y="0" width="183" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Name]]></text>
            </staticText>
            <staticText>
                <reportElement x="354" y="0" width="172" height="20"/>
                <textElement textAlignment="Center" verticalAlignment="Middle"/>
                <text><![CDATA[Address]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="11" y="0" width="160" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{idClient}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="354" y="0" width="172" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="171" y="0" width="183" height="20"/>
                <box leftPadding="10"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

The result will be (the report exported to pdf format):

The report in PDF format

UPDATE:

For filling header with company info you can use the Group band. You can read info about groups here.

You query will be like this:

SELECT c.idClient, c.name, c.address, cmp.name AS companyName, cmp.contactInfo, cmp.id AS idCompany FROM customers c, companies cmp WHERE cmp.id=c.idCompany SORT BY cmp.id

You should also add report's fields for data from companies table (companies.name, companies.contactInfo, companies.id, for example):

    <field name="companyName" class="java.lang.String"/>
    <field name="contactInfo" class="java.lang.String"/>
    <field name="idCompany" class="java.lang.String"/>

After that you should add group by idCompany (the unique key from companies table).
And then put the textField elements with fields (companyName, contactInfo) to the Group band.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文