How to set background color of a column in Jasper Report - jasper-reports

<staticText>
<reportElement x="100" y="0" width="100" height="25" backcolor="#A6A6A6" />
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Nom]]></text>
</staticText>
I need to change the background color, i tried the attribute " backcolor="#A6A6A6" " but it it doesn't work!

You also need to set mode="Opaque".

Related

Jasper Report text new line when Chinese+number String overflow lose

I use traditional Chinese ,and set the Stretch with overflow.
I find the Jasper report lose some characters like above picture when it would create a new line.
my jrxml text :
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="352" y="0" width="140" height="30" isPrintWhenDetailOverflows="true" uuid="9855b06a-dfca-4a88-8830-efb1590c2d4e"/>
<box topPadding="1" leftPadding="4" bottomPadding="5" rightPadding="4">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="標楷體" pdfFontName="MHei-Medium" pdfEncoding="UniCNS-UCS2-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single" lineSpacingSize="1.1"/>
</textElement>
<textFieldExpression><![CDATA[$F{varyReason}]]></textFieldExpression>
</textField>
Do I lose some setting???

Is it possible to have a variable as value in Jasper XML

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"/>

Remove space between detail and last page footer

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

Merging the cells which have same data

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"

Hiding the field in jasper report

I am working with jasper report-4.5.0.I want to hide a field in jasper based on the flag value.Below is tha code which i am using in columnHeader band.
<staticText>
<reportElement x="365" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
and below code i am using in detail band.
<textField>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[!$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{chargeTotal}]]></textFieldExpression>
</textField>
i am declaring the parameter in jrxml as
<parameter name="dataType" class="java.lang.Boolean"/>
the value to this parameter is coming from java class.If it is the false value i dont want to display this chargeTotal column.What i am doing wrong in my code.I am not getting.Any one can point me where i am doing wrong its urgent to me.
The code snippets you provided for the textfield look correct, but if you are wanting to hide the column header also you need to also add a printWhenExpression for it.
<staticText>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
Edit: Actually, you have the conditional value backwards. If you want to show the column when dataType is true, your printWhenExpression needs to look like:
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>