Jump to content
We've recently updated our Privacy Statement, available here ×

Adding Style Dynamically


gujralam

Recommended Posts

Hi All,

I am new to Jasper and I need your assistance for resolving a problem.

I am creating a Excel file using Jasper Reports.

I have a requirement by which I need to change the FONT color based on value of a field.

E.g. In the TextExpression below, if the value of the the field, JOBSTATUS, is 'Completed' the text (Completed) should be displayed in GREEN,

But if the value of the field, JOBSTATUS, is 'Failed', the text (Failed) should be displayed in RED,

<textFieldExpression   class="java.lang.String"><![CDATA[($F{DISPLAYFLAG}.equals("F")?"NOT TO BE RUN FOR THE DAY":($F{JOBSTATUS}.equals("I")?"COMPLETED":($F{JOBSTATUS}.equals("X")?"CANCELLED":($F{JOBSTATUS}.equals("R")?"RUNNING":($F{JOBSTATUS}.equals("F")?"FAILED":($F{JOBSTATUS}.equals("C")?"COMPLETED":"N.A."))))))]]></textFieldExpression>

Please can you guide me how to go about designing my JRXML in this case.

I donot want to make any changes in the JAVA.

Thanks in advance for your help !!

 

Code:
<textFieldExpression   class="java.lang.String"><![CDATA[($F{DISPLAYFLAG}.equals("F")?"NOT TO BE RUN FOR THE DAY":($F{JOBSTATUS}.equals("I")?"COMPLETED":($F{JOBSTATUS}.equals("X")?"CANCELLED":($F{JOBSTATUS}.equals("R")?"RUNNING":($F{JOBSTATUS}.equals("F")?"FAILED":($F{JOBSTATUS}.equals("C")?"COMPLETED":"N.A."))))))]]></textFieldExpression>
Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi Axel,

Thank you for the suggestion and I apologise for the late response.

I tried the following and it worked nicely on excel  and now I am able to change the colors

 1. In the textelement put masrkup as styled

and then

2. Add <style forecolor=\"black\"> </style> in the CDATA section

Please see below for details.

Once again appreciate your suggestion. Any pointers to a nice tutorial on your suggestion would be welcomed.

Regards

Amit

 

 

Code:
                    <textElement markup="styled">                        <font size="8"/>                    </textElement>                    <textFieldExpression   class="java.lang.String"><![CDATA[($F{DISPLAYFLAG}.equals("F")?"<style  forecolor=\"darkGray\">NOT TO BE RUN FOR THE DAY</style>":($F{JOBSTATUS}.equals("I")?"<style forecolor=\"black\">COMPLETED</style>":($F{JOBSTATUS}.equals("X")?"<style isBold=\"true\" forecolor=\"blue\">CANCELLED</style>":($F{JOBSTATUS}.equals("R")?"<style isBold=\"true\" forecolor=\"yellow\">RUNNING</style>":($F{JOBSTATUS}.equals("F")?"<style isBold=\"true\" forecolor=\"red\">FAILED<style>":($F{JOBSTATUS}.equals("C")?"<style forecolor=\"black\">COMPLETED</STYLE>":"N.A."))))))]]></textFieldExpression>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...