anand0303 Posted October 5, 2011 Share Posted October 5, 2011 Hi all,I am trying to set the backcolor property of a particular field in my report using the following expression:($F{BUDGETED_HOURS}.equals( "NA" ))? $F{PLANNED_HOURS}:( $F{PLANNED_HOURS}.equals( "NA" )? $F{PLANNED_HOURS}: ( Double.parseDouble($F{PLANNED_HOURS}) > Double.parseDouble($F{BUDGETED_HOURS})? "<style backcolor='#FF0000' isBold='true'>" + $F{PLANNED_HOURS}.toString()+"</style>" : $F{PLANNED_HOURS}))As seen above, I have tried to set both the backcolor and isbold properties. When exported to excel file, I can see the text getting set to bold but cannot see the backcolor getting applied.I tried setting some more properties like FORECOLOR, UNDERLINE etc.. all of them gets applied except the backcolor.I am trying to view the exported xls in Openoffice.For this particular field I have set opaque = true and markup = styled.The logic for exporting to xls is as below:JRXlsExporter exporterXls = new JRXlsExporter();exporterXls.setParameter(JRXlsExporterParameter.JASPER_PRINT,jp);exporterXls.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, xlsReport);exporterXls.exportReport(); bytes = xlsReport.toByteArray(); response.setContentType("application/xls"); response.setContentLength(bytes.length); response.setHeader("Content-Disposition", "attachment;filename=Report.xls"); out.write(bytes, 0, bytes.length); out.flush(); out.close();My ireport version is 4.0 Please help.Thanks in advance. Link to comment Share on other sites More sharing options...
lknueve Posted October 6, 2011 Share Posted October 6, 2011 when viewing the report in your internal viewer, is it showing the background color properly? I'm also only seeing 1 "else" statement to your 3 "if" statements -> is that intentional? Could the formula be looking for an "else" statement that doesn't exist? Link to comment Share on other sites More sharing options...
lknueve Posted October 6, 2011 Share Posted October 6, 2011 scratch that about the "else" stmts - I didn't notice the ":" at the end of the lines.... Link to comment Share on other sites More sharing options...
lknueve Posted October 6, 2011 Share Posted October 6, 2011 could it also be true that the budgeted_hours field is null? that would affect results as well Link to comment Share on other sites More sharing options...
anand0303 Posted October 7, 2011 Author Share Posted October 7, 2011 Hi all,Thanks for your responses.The values are getting displayed correctly and the null conditions are also handled properly.I have set two different properties here: backcolor and isbold. The isbold (and some others like forecolor etc) works absolutely fine. The issue occurs only with the backcolor property. Regards Link to comment Share on other sites More sharing options...
anand0303 Posted October 7, 2011 Author Share Posted October 7, 2011 Hi,Please do refer to the attachments below.I have set a very simple expression in the textfieldexpression property for that particular field:"<style isDefault='false' mode='Opaque' backcolor='#FF0000'>" + $F{PLANNED_HOURS} + "</style>"The results of internal preview and the xls generated by ireport using openoffice installed on my machine are attached. Please advice. Link to comment Share on other sites More sharing options...
lknueve Posted October 10, 2011 Share Posted October 10, 2011 let me play with this some more tomorrow -hopefully I can find something Link to comment Share on other sites More sharing options...
Cralevic Posted October 12, 2011 Share Posted October 12, 2011 Hi,have you tried for example backcolor='red' instead of color number?Open Office has some bugs with displayed colors. I use in my exports colors [191,225,255] or [204,192,218], but now I don't know their number ... Hope it'll help you somehow. Link to comment Share on other sites More sharing options...
Cralevic Posted October 12, 2011 Share Posted October 12, 2011 The other workaround I have used is simple but not very comfortable. I have two cells with same source, one has white background the oher has red backgroud color in property "backcolor". According to value in specified column I show the "white" or the "red" cell using condition in property "print when expression". Cralevic current IReport version 4.1.2 Link to comment Share on other sites More sharing options...
anand0303 Posted October 12, 2011 Author Share Posted October 12, 2011 Hi Cralevic ,Thanks for your reply.Do you mean 'field' when you say 'cell'?Do I need to provide the same field twice for the particular column with one of them having backcolor = red?Can you please provide some sample code for the same? That will be really helpful. Regards Link to comment Share on other sites More sharing options...
Cralevic Posted October 12, 2011 Share Posted October 12, 2011 Hi Anand,yep I mean field. Yes exactly. Tomorrow I'll post some pictures and code. Those two fields should be on the each other. Cralevic current IReport version 4.1.2 Link to comment Share on other sites More sharing options...
Cralevic Posted October 13, 2011 Share Posted October 13, 2011 Hi Anand, as I promise I enclose pictures and code. In the final screen I put those two fields to each other.Do not hesitate to contact me again :-) CralevicWrote: Hi Anand, yep I mean field. Yes exactly. Tomorrow I'll post some pictures and code. Those two fields should be on the each other. Cralevic current IReport version 4.1.2 Code:<?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="condition" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <property name="ireport.zoom" value="1.0"/> <property name="ireport.x" value="0"/> <property name="ireport.y" value="0"/> <queryString> <![CDATA[sELECT show, val FROM (SELECT 'Y' as show, sysdate as val FROM dual UNION ALL SELECT 'N' as show, sysdate as val FROM dual)]]> </queryString> <field name="SHOW" class="java.lang.String"/> <field name="VAL" class="java.sql.Timestamp"/> <background> <band splitType="Stretch"/> </background> <title> <band splitType="Stretch"/> </title> <pageHeader> <band splitType="Stretch"/> </pageHeader> <columnHeader> <band height="42" splitType="Stretch"> <staticText> <reportElement x="0" y="22" width="100" height="20"/> <textElement/> <text><![CDATA[sHOW]]></text> </staticText> <staticText> <reportElement x="100" y="22" width="100" height="20"/> <textElement/> <text><![CDATA[VAL]]></text> </staticText> </band> </columnHeader> <detail> <band height="21" splitType="Stretch"> <textField> <reportElement x="0" y="0" width="100" height="20"/> <box> <bottomPen lineWidth="1.0"/> </box> <textElement> <font size="10"/> </textElement> <textFieldExpression><![CDATA[$F{SHOW}]]></textFieldExpression> </textField> <textField> <reportElement x="100" y="0" width="100" height="20"> <printWhenExpression><![CDATA[$F{SHOW}.equals( "Y" )]]></printWhenExpression> </reportElement> <box> <bottomPen lineWidth="1.0"/> </box> <textElement/> <textFieldExpression><![CDATA[$F{VAL}]]></textFieldExpression> </textField> <textField> <reportElement mode="Opaque" x="100" y="0" width="100" height="20" backcolor="#FF0033"> <printWhenExpression><![CDATA[$F{SHOW}.equals( "N" )]]></printWhenExpression> </reportElement> <box> <bottomPen lineWidth="1.0"/> </box> <textElement/> <textFieldExpression><![CDATA[$F{VAL}]]></textFieldExpression> </textField> </band> </detail> <columnFooter> <band splitType="Stretch"/> </columnFooter> <pageFooter> <band splitType="Stretch"/> </pageFooter> <summary> <band splitType="Stretch"/> </summary></jasperReport> Link to comment Share on other sites More sharing options...
anand0303 Posted October 13, 2011 Author Share Posted October 13, 2011 Hi Cralevic,Thanks a lot for your assistance.I will try the way you have suggested and will surely get back to you accordingly.One small question, are you able to see the backcolor getting displayed if you set the preview type to XLS PREVIEW? Regards Link to comment Share on other sites More sharing options...
Cralevic Posted October 13, 2011 Share Posted October 13, 2011 HI Anand,yep I'm. I enclose even .xls file.Craleviccurrent IReport version 4.1.2 Link to comment Share on other sites More sharing options...
anand0303 Posted October 14, 2011 Author Share Posted October 14, 2011 Hi Cralevic,Thanks for your wonderful suggestions.I was able to implement this workaround and could see the backcolor getting set in the exported xls file.There seems to be an issue with iReport itself when we try to set the backcolor directly using expressions.I have tested the implementation in OpenOffice. Will test them in MSOffice too.Will get back in case I need any assistance.Thanks again.Regards 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