I want to make a table with dynamic headers for a PDF in Grails using Jasper. One of the possible solutions would be to have a property as a value for an xml attribute. I have a hard time explaining it in English,so maybe it's better to leave an example, here is the xml code for a static header in a table:
<staticText>
<reportElement x="29" y="183" width="118" height="32"/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Column header text]]></text>
</staticText>
What I want to know is, is it possible to have a parameter for the value of x, y and every other attribute value for the element, like for an example this:
<staticText>
<reportElement x="<![CDATA[$P{columnX}]]>" y="<![CDATA[$P{columnY}]]>" width="<![CDATA[$P{columnWidth}]]>" height=32/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Column header text]]></text>
</staticText>
The parameter would be declared like this:
<parameter name="columnX" class="java.lang.Long"/>
Some attribute character is coming in the next line.it should come in one line
Example:
Student looking like
Student
but name is looking like
nam
e
The code is
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="200" height="21" uuid="e3b2f0ba-d810-42d5-aad6-74b440e871c6"/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement>
<font fontName="SansSerif" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
How i can remove the space between detail and last page footer in JasperReports?
I need to remove the white space between them
I use this code for lastpagefooter
<lastPageFooter>
<band height="187">
<staticText>
<reportElement x="125" y="0" width="68" height="20" uuid="d7bc9c8a-c20b-4f79-8515-639609ead0cc"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[المجموع : ]]></text>
</staticText>
<textField>
<reportElement x="35" y="0" width="90" height="20" uuid="4b93f507-3e79-4ba7-99ce-d65b64a1a78b"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{Totals}]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="23" y="167" width="40" height="20" uuid="c0c0de0b-7bb5-4133-bf5e-dfe51f91dac4"/>
<box rightPadding="2"/>
<textElement textAlignment="Right"/>
</band>
</lastPageFooter>
http://www.gulfup.com/?lV8MpF
This is the file
I just change the propriety of report Ignore pagination to true
<jasperReport ... isIgnorePagination="true" ...>
The problem in this case that i can't use breakI want to break to a new page when the number of the rows
finally, I use group footer and i add the total in it
I have a conversion from jrxml to pdf. I am sending the data as 001 in the DTO but while displaying the same in the Excel it is becoming as 1. Below is the code that is been used for displaying the data.
Code:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="table 5_CH" stretchType="RelativeToTallestObject" x="0" y="0" width="71" height="26" backcolor="#FFFFFF">
<property name="class" value="sortable"/>
</reportElement>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font pdfFontName="Helvetica"/>
<paragraph lineSpacing="Single" firstLineIndent="3" spacingAfter="5"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{reference}]]>
</textFieldExpression>
</textField>
I need to show the leading zeros also. So pls let me know how to fix this issue.
You are using the MS Excel application for viewing csv file. The csv is just a plain-text format, it does not contain information "how to show data". The view of this sort of data depends on your viewer only. Therefore you can try to use JRXlsExporter or JExcelApiExporter or JRXlsxExporter exporters - for constructing report in Excel format (xls or xlsx).
Let's look at an example. We take csv file as datasource.
The csv file data (excel_data.csv):
number_as_string,date,number_as_int
001,2013-09-23,1
002,2013-09-22,3
3,2013-09-21,4
004,2013-09-20,5
The configuration of datasource in iReport will be:
We will use the net.sf.jasperreports.export.xls.pattern and net.sf.jasperreports.export.xls.detect.cell.type properties in sample for getting information in format we want.
Our template will be:
<?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="test_excel_formatting" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="952b781d-520d-4a76-aa59-f635b8759fbe">
<property name="net.sf.jasperreports.export.xls.detect.cell.type" value="true"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="number_as_string" class="java.lang.String"/>
<field name="date" class="java.util.Date"/>
<field name="number_as_int" class="java.lang.Integer"/>
<columnHeader>
<band height="42" splitType="Stretch">
<staticText>
<reportElement uuid="667b6ca6-bf50-404e-8ef1-c654456ed8e4" stretchType="RelativeToTallestObject" mode="Opaque" x="0" y="0" width="88" height="42" backcolor="#FF99CC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Number as String, without pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="080a5cc0-fa66-4b11-a3d3-f0b8a4e69204" stretchType="RelativeToTallestObject" mode="Opaque" x="88" y="0" width="88" height="42" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Number as Int, without pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="d1fc6219-2e33-4cc9-b4fe-4ac2b5365102" stretchType="RelativeToTallestObject" mode="Opaque" x="176" y="0" width="104" height="42" backcolor="#99FFCC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Date without pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="991837d7-a1ab-44ed-8177-756cfae9d369" stretchType="RelativeToTallestObject" mode="Opaque" x="280" y="0" width="104" height="42" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Number as Int with common pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="d38154af-2017-4e10-a176-4d66e5cc9f96" stretchType="RelativeToTallestObject" mode="Opaque" x="384" y="0" width="104" height="42" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Number as Int with xls pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="17f57019-8691-4643-abdb-ab15afe63f36" stretchType="RelativeToTallestObject" mode="Opaque" x="488" y="0" width="104" height="42" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Number as Int with common and xls pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="f4f506bf-9511-4e1e-805b-8752a98e91ea" stretchType="RelativeToTallestObject" mode="Opaque" x="592" y="0" width="104" height="42" backcolor="#99FFCC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Date with common pattern]]></text>
</staticText>
<staticText>
<reportElement uuid="dffea96e-1dfa-47e0-8551-dd417c25ecbd" stretchType="RelativeToTallestObject" mode="Opaque" x="696" y="0" width="104" height="42" backcolor="#99FFCC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Date with common pattern]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement uuid="3d11d568-6e2c-4373-af7d-fa79b99a2908" mode="Opaque" x="0" y="0" width="88" height="20" backcolor="#FF99CC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{number_as_string}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="8b8f968e-ca6d-44d0-bc2e-50a4773d0a6f" mode="Opaque" x="88" y="0" width="88" height="20" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{number_as_int}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="943a468b-491d-4955-b0c0-58d550536234" mode="Opaque" x="176" y="0" width="104" height="20" backcolor="#99FFCC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<textField pattern="000000">
<reportElement uuid="52a26b66-1ef5-4f77-a4a2-900a606a1171" mode="Opaque" x="280" y="0" width="104" height="20" backcolor="#9999FF"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{number_as_int}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c26be152-fae4-4a85-ae55-c70e27739a87" mode="Opaque" x="384" y="0" width="104" height="20" backcolor="#9999FF">
<property name="net.sf.jasperreports.export.xls.pattern" value="00000000000000"/>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{number_as_int}]]></textFieldExpression>
</textField>
<textField pattern="00000">
<reportElement uuid="fab0fba1-1718-479d-841b-6cbaf1963a0b" mode="Opaque" x="488" y="0" width="104" height="20" backcolor="#9999FF">
<property name="net.sf.jasperreports.export.xls.pattern" value="00000000000000"/>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{number_as_int}]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yyyy">
<reportElement uuid="07552f94-56c8-413d-8dd8-5b5c667c81cf" mode="Opaque" x="592" y="0" width="104" height="20" backcolor="#99FFCC"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="844449f9-1578-4729-b911-18bdd17f8cd4" mode="Opaque" x="696" y="0" width="104" height="20" backcolor="#99FFCC">
<property name="net.sf.jasperreports.export.xls.pattern" value="dd mmmm yyyy"/>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The report's design in iReport looks like this:
In example I've set report's property net.sf.jasperreports.export.xls.detect.cell.type as true.
I've put the number_as_string field without any patterns into the first column (pink color).
I've put the number_as_int field into the columns number 2, 4, 5, 6 (blue color).
The column #2 does not contain any pattern.
The column #4 does contains common textFields element's pattern attribute. I've used the 000000 value.
For column #5 I've set net.sf.jasperreports.export.xls.pattern property. I've set 00000000000000 value for it.
And the column #6 is a mixed variant - I've set net.sf.jasperreports.export.xls.pattern property and the textFields element's pattern.
I've put the date field into the columns number 3, 7, 8 (green color).
The column #3 does not contain any pattern. The default pattern will be used.
The column #7 does contains common textFields element's pattern attribute. I've used the dd-MMM-yyyy value.
For column #8 I've set net.sf.jasperreports.export.xls.pattern property. I've set dd mmmm yyyy value for it.
The result (generated file in Excel format) will be:
Notes:
As you can see the first column contains data in original format.
The column #6 contains data in format set with help of net.sf.jasperreports.export.xls.pattern property. This property is "stronger" than the textFields element's pattern attribute.
The Excel file was generated with help of iReport 5.2.0 with XLS Preview, XLS Preview (Using JExcel API) and Excel 2007 (XLSX) Preview options - the result was the same.
I figured the answer after lot of googling. I am sending the data as String but still it is truncating the leading zeroes.
The problem is, excel is taking this input as a number and truncating the leading zeros.
In order to stop excel from doing this, prefix the data with '=' and append our data in double quotes.
i.e, the input which I am sending is 001 which should be converted as "=" + "\"" + "001" + "\"" so it becomes ="001" then in excel it gets to know that the given one is a text and it is not going to truncate the leading zeroes.
Addendum:
I even had trouble while displaying the date. The requirement is, date should be displayed as 04 Apr 2013 but if I send the same to excel it is converting it to 04-Apr-2013 which is not acceptable in my case.
The same logic above holds good here too,
just append '=' to the input data. Say "=" + "\"" + 04 Apr 2013 + "\"" so it becomes
="04 Apr 2013". Now the date is taken as a textand is displayed as it is.
Hoping this will help someone .. :)
I have a report which has the columns Type,S.No,Date.Here the Type column will have the same value for all rows.So i just want to merge all the cells of Type column.I have referred the below link
Group several same value field into a single cell
and tried with their suggestion.But if i do like that i am getting like in below image.
Edit:
Below is the code i am using in my jrxml for merging the cells which have same data.
<field name="type" class="java.lang.String"/>
<group name="type">
<groupExpression><![CDATA[$F{type}]]></groupExpression>
</group>
In detail band i tried by creating the fake statictext behind the type textfield like below.
<staticText>
<reportElement x="0" y="0" width="121" height="20"/>
<box>
<leftPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement/>
<text><![CDATA[]]></text>
</staticText>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="121" height="20"/>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
Tried by using printWhenExpression in type textfield like below.
<textField>
<reportElement x="0" y="0" width="121" height="20">
<printWhenExpression><![CDATA[$V{type_COUNT} == 1]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.0"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.0"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{type}]]></textFieldExpression>
</textField>
But no use.
If i add the bottom border for static text then the image looks like below.
Thank You.
Add the bottom border in GroupFooter band for group "type"