Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>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? </p> </blockquote> <p>You can look at <a href="http://jasperreports.sourceforge.net/sample.reference.html" rel="nofollow noreferrer">this samples</a>. The <a href="http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.5.0/" rel="nofollow noreferrer">JasperReports distribution package</a> contains many others samples (in folder <em>%jasperreports%\demo\samples</em>). The <em>iReport</em> has also several samples in folder <em>%iReport%\ireport\samples</em>.</p> <p>Your sample report is very simple. </p> <p>The steps for creating the such report can be like this:</p> <ol> <li>Adding <em>image</em> element (with company logo) and several (or one) <em>staticText</em> elements (with company contact information) to the <em>Title</em> band.</li> <li>Adding query (for getting data from <em>MySQL</em> DB) with fields (<em>idClient</em>, <em>name</em>, <em>address</em> in your sample)</li> <li>Adding <em>staticText</em> elements with columns header to the <em>Column header</em> band - it will be the columns header for data grid</li> <li>Adding <em>textField</em> elements with fields to the <em>Detail</em> band - it will be the data in grid</li> </ol> <p>You should read the <em><a href="http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf" rel="nofollow noreferrer">JasperReports Ultimate Guide</a></em>. It is a great tutorial.</p> <p>The sample <em>jrxml</em> file (designed in <em>iReport</em>):</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;queryString&gt; &lt;![CDATA[SELECT idClient, name, address FROM customers_table]]&gt; &lt;/queryString&gt; &lt;field name="idClient" class="java.lang.Integer"/&gt; &lt;field name="name" class="java.lang.String"/&gt; &lt;field name="address" class="java.lang.String"/&gt; &lt;title&gt; &lt;band height="108" splitType="Stretch"&gt; &lt;staticText&gt; &lt;reportElement x="171" y="53" width="183" height="55"/&gt; &lt;textElement textAlignment="Center" verticalAlignment="Middle" markup="styled"/&gt; &lt;text&gt;&lt;![CDATA[&lt;style isBold="true" forecolor="blue"&gt;ABC COMPANY&lt;/style&gt; Main Avenue and 9th Street Tel: (593) 4 - 2066765 e-mail: info@abc.com]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;image&gt; &lt;reportElement x="245" y="3" width="41" height="50"/&gt; &lt;imageExpression&gt;&lt;![CDATA["abc_logo.png"]]&gt;&lt;/imageExpression&gt; &lt;/image&gt; &lt;/band&gt; &lt;/title&gt; &lt;columnHeader&gt; &lt;band height="20"&gt; &lt;staticText&gt; &lt;reportElement x="11" y="0" width="160" height="20"/&gt; &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt; &lt;text&gt;&lt;![CDATA[Id Client]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;staticText&gt; &lt;reportElement x="171" y="0" width="183" height="20"/&gt; &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt; &lt;text&gt;&lt;![CDATA[Name]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;staticText&gt; &lt;reportElement x="354" y="0" width="172" height="20"/&gt; &lt;textElement textAlignment="Center" verticalAlignment="Middle"/&gt; &lt;text&gt;&lt;![CDATA[Address]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;/band&gt; &lt;/columnHeader&gt; &lt;detail&gt; &lt;band height="20" splitType="Stretch"&gt; &lt;textField&gt; &lt;reportElement x="11" y="0" width="160" height="20"/&gt; &lt;box leftPadding="10"/&gt; &lt;textElement/&gt; &lt;textFieldExpression&gt;&lt;![CDATA[$F{idClient}]]&gt;&lt;/textFieldExpression&gt; &lt;/textField&gt; &lt;textField&gt; &lt;reportElement x="354" y="0" width="172" height="20"/&gt; &lt;box leftPadding="10"/&gt; &lt;textElement/&gt; &lt;textFieldExpression&gt;&lt;![CDATA[$F{name}]]&gt;&lt;/textFieldExpression&gt; &lt;/textField&gt; &lt;textField&gt; &lt;reportElement x="171" y="0" width="183" height="20"/&gt; &lt;box leftPadding="10"/&gt; &lt;textElement/&gt; &lt;textFieldExpression&gt;&lt;![CDATA[$F{address}]]&gt;&lt;/textFieldExpression&gt; &lt;/textField&gt; &lt;/band&gt; &lt;/detail&gt; &lt;/jasperReport&gt; </code></pre> <p>The result will be (the report exported to <em>pdf</em> format):</p> <p><img src="https://i.stack.imgur.com/11ZjG.png" alt="The report in PDF format"></p> <p><strong><em>UPDATE:</em></strong></p> <p>For filling header with company info you can use the <em>Group</em> band. You can read info about groups <a href="http://jasperreports.sourceforge.net/sample.reference/jasper/index.html#groups" rel="nofollow noreferrer">here</a>.</p> <p>You query will be like this: </p> <pre class="lang-sql prettyprint-override"><code>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 </code></pre> <p>You should also add report's <em>fields</em> for data from <em><code>companies</code></em> table (<em><code>companies.name</code></em>, <em><code>companies.contactInfo</code></em>, <em><code>companies.id</code></em>, for example):</p> <pre><code> &lt;field name="companyName" class="java.lang.String"/&gt; &lt;field name="contactInfo" class="java.lang.String"/&gt; &lt;field name="idCompany" class="java.lang.String"/&gt; </code></pre> <p>After that you should add <em>group</em> by <em><code>idCompany</code></em> (the unique key from <em><code>companies</code></em> table). And then put the <em>textField</em> elements with fields (<em><code>companyName</code></em>, <em><code>contactInfo</code></em>) to the <em>Group</em> band.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload