Jasper report XLS export shows value as String instead of Currency - jasper-reports

I have a similar issue as described here but with the value type instead of value pattern. I have a value called 'Balance'
<parameter name="Balance" class="java.lang.String"/>
and corresponding field
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="400" y="55" width="117" height="7"/>
<textElement textAlignment="Right" verticalAlignment="Top">
<font size="7" isBold="true" pdfFontName="Helvetica" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression><![CDATA[( $P{Balance}.equals(null) ? "" : $P{Balance} )]]></textFieldExpression>
</textField>
When I export my Jasper report as XLS, 'Balance' value comes in correct pattern (ie. $400.20) but Excel consider this as a String instead of Currency.
Any idea how to fix it would be much appreciated.

Related

Dynamic content in text field in JRXML file

Below is the code snippet
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="381" y="242" width="79" height="18" forecolor="#000000" backcolor="#FFFFFF" uuid="4ec23e25-c8d9-4941-bd81-777aff6c08a7">
<reportElement/>
<text><![CDATA[14.01.2019]]></text>
</staticText>
Each month we need to change the date in JRXML file manually <text><![CDATA[14.01.2019]]></text> as 14.11,14,12 etc.
How can I automate this feature? Like code will read the current system date, once it reaches 14th of the month , automatically the date will change in jrxml file as well?
Please help.
You could turn the staticText into a textField where you could use an expression based on JasperReports built-in date/time functions, like so:
<textField>
<reportElement key="staticText-2" mode="Opaque" x="381" y="242" width="79" height="18" forecolor="#000000" backcolor="#FFFFFF" uuid="4ec23e25-c8d9-4941-bd81-777aff6c08a7"/>
<textFieldExpression><![CDATA[DATEFORMAT(EDATE($P{AccountingDate}, 1), "14.MM.yyyy")]]></textFieldExpression>
</textField>

Text truncated on JasperReports

I have a JasperReports's report within an application that is truncating text and I am unsure how to get it to display the full name.
The code snippet below shows that I have included isStretchWithOverflow="true":
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="353" y="0" width="79" height="30"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{acname}]]></textFieldExpression>
</textField>
The JasperReports's image shows incorrect values. One of these should read: 'Double Time Pay - Bill Regular' and the other 'Double Time Pay - Bill Overtime'.

Jasper report in displaying arabic

This is my xml tag for jasper
<textField>
<reportElement x="56" y="0" width="276" height="20" uuid="952b2fc3-7220-40ed-80eb-e2a3b9fd9fe2"/>
<textElement>
<font fontName="DejaVu Sans" pdfFontName="Courier" pdfEncoding="Cp1256" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[new String($F{TEST}.getBytes(), "UTF-8")]]></textFieldExpression>
</textField>
Input:
واحد مائة أَلْفٌ درهم اماراتي
Output:
واحد مائة ?? درهم اماراتي
We can see two question marks in place of arabic character that stands for 1000.
How to display this?
Where I am wrong?
I only use Arial Unicode to handle Arabic. I see you are using DejaVu Sans.

Print a field when certain value is not present Jasper reports

I am creating a JasperReports's report using iReport. I have a date field where once instance is 01-JAN-1900. I need any time the date field has this value then null value is printed. I have tried this:
<textField pattern="dd-MMM-yyyy" isBlankWhenNull="true">
<reportElement uuid="4dd05795-8363-4cf3-ad30-239aac3a086f" x="3" y="0" width="63" height="15">
<printWhenExpression><![CDATA[$F{TRAN_DATE} != "01-JAN-1900"]]></printWhenExpression>
</reportElement>
<textElement>
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{TRAN_DATE}]]></textFieldExpression>
</textField>
But the value is still getting printed. How do I achieve this?
You cannot compare dissimilar types. Drop the String literal and compare datetime types.
If your field $F{TRAN_DATE} is in java.util.Date type, change it to java.lang.String and your condition should work.

Formatting/Pattern issue - Appending the Int with text is causing formatting error

So I am running into issues with JasperReports pattern field. I have created a cross tab and I need all $F{ScoreMeasure} to have two decimal places and appended with a "%" sign. So for example a cell for the $F{ScoreMeasure} in the crosstab should show 25.42%.
The issue I have come across is I appended the "%" sign by adding it to the text field expression:$V{ScoreMeasure}+"%". This works fine with whole numbers.
When I try add the two decimal places by adding the pattern #,##0.00 and run the report I get some fields have two decimals and others have multiple (up to 8).
If I drop the appended text (+"%") from the text field expression I get the right format. But I cant work out how to get the two?
Here's an extract of when it is working without the "%" appended:
<crosstabCell width="73" height="25" rowTotalGroup="Name">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField pattern="#,##0.00">
<reportElement style="Crosstab Data Text" x="0" y="0" width="73" height="25" forecolor="#FFFFFF" uuid="50401fd4-b9b1-4bf2-bd74-9a0f083e77ff"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$V{ScoreMeasure}
]]></textFieldExpression>
</textField>
</cellContents>
And here it is appended with the text which is breaking the format:
<crosstabCell width="73" height="25" rowTotalGroup="Name">
<cellContents backcolor="#005FB3" mode="Opaque">
<box>
<pen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField pattern="#,##0.00">
<reportElement style="Crosstab Data Text" x="0" y="0" width="73" height="25" forecolor="#FFFFFF" uuid="50401fd4-b9b1-4bf2-bd74-9a0f083e77ff"/>
<textElement verticalAlignment="Middle">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$V{ScoreMeasure}+"%"
]]></textFieldExpression>
</textField>
</cellContents>
Anyone come across this? Any suggestions on how to fix?
Okay so the solution was in the pattern I selected "Custom Format" I then added the pattern for two decimal places ###0.00 and tried appending it with the % sign. So my custom pattern looked like ###0.00%;-###0.00%.
But when this is run it multiplied the figure bu 100. It turns out "The presence of the percentage character in the pattern causes the value to be multiplied by 100 before being formatted."
So in order to avoid this you add quotes around the % sign. So your final pattern looks like this: ###0.00'%';-###0.00'%'
When run you will then get your two decimal place with the % sign
How about clicking on the field you want to customized.
Go to Properties
Go to Pattern then click on the Number -> click on Decimal for 2 spaces
Then Press OK.
Then go back to the Pattern again and go to Custom Format.
Then put a percentage in the text field for the positive and negative part
Then press ok.
EDIT
How about making the Field a string and then append the percent sign like:
$F{ScoreMeasure}.toString()+"%"