gujralam Posted November 3, 2009 Share Posted November 3, 2009 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 More sharing options...
ahallez Posted November 3, 2009 Share Posted November 3, 2009 If you can't style an element dynamically, you could add one element per style that you want to display and use printWhenExpressions to decide which one should be visible.Axel Hallez Link to comment Share on other sites More sharing options...
gujralam Posted November 7, 2009 Author Share Posted November 7, 2009 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 styledand then 2. Add <style forecolor=\"black\"> </style> in the CDATA sectionPlease see below for details.Once again appreciate your suggestion. Any pointers to a nice tutorial on your suggestion would be welcomed.RegardsAmit 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now