Wednesday 15 July 2020

Tip : Part of text "red" in color with "underscore" for Text field expression in Jaspersoft reports Or Styled Markup example in Jasper Studio

Problem Statement : 
Get part of text "red" in color with "underscore" for text field expression

Solution : 
Use "styled" Markup on text field with expression written with "style" tag. 

Text field expression: 
"Hi, This is regurlar text"+"<style forecolor=\"red\" isUnderline=\"true\">Styled Markup for red color text with underscore in Text Field Expression</style>"+"  This is normal text "+"\n"+"no later than the following date: "+"<style forecolor=\"red\">This text is in red color without underscore</style>"


Sample jrxml design (Tap onto the image for better visibility)

Sample report output(Tap onto the image for better visibility)
JRXML(works from 7.2 studio professional)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0  -->
<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="Styled Markup for red color text with underscore in Text Field Expression" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
	<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
	<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
	<property name="ireport.jasperserver.url" value="https://dev-lockton-cms.seventablets.com/jasperserver-pro/"/>
	<property name="ireport.jasperserver.user" value="superuser"/>
	<property name="ireport.jasperserver.report.resource" value="/organizations/organization_1/Lockton_Reports_1/Test/Styled_Markup_for_red_color_text_with_underscore_in_Text_Field_Expression_files/main_jrxml"/>
	<property name="ireport.jasperserver.reportUnit" value="/organizations/organization_1/Lockton_Reports_1/Test/Styled_Markup_for_red_color_text_with_underscore_in_Text_Field_Expression"/>
	<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
	<property name="com.jaspersoft.studio.unit." value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
	<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
	<queryString language="SQL">
		<![CDATA[]]>
	</queryString>
	<summary>
		<band height="460" splitType="Stretch">
			<property name="com.jaspersoft.studio.unit.height" value="px"/>
			<textField>
				<reportElement x="50" y="25" width="530" height="40" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
				<textElement verticalAlignment="Bottom">
					<font fontName="Garamond" size="16" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA["Styled Markup for red color text with underscore in Text Field Expression"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement mode="Opaque" x="30" y="100" width="35" height="35" forecolor="#FFFFFF" backcolor="#000000" uuid="3edcc7ee-d3fa-4bc7-a02e-d7744e776592">
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
				</reportElement>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font fontName="Garamond" size="16" isItalic="true"/>
				</textElement>
				<textFieldExpression><![CDATA["1"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="65" y="100" width="485" height="35" uuid="3261f9a0-a9c6-460e-9943-87c9c3cd2dad">
					<property name="com.jaspersoft.studio.unit.height" value="px"/>
				</reportElement>
				<box leftPadding="10"/>
				<textElement textAlignment="Left" verticalAlignment="Middle" markup="styled"/>
				<textFieldExpression><![CDATA["Hi, This is regurlar text"+"<style forecolor=\"red\" isUnderline=\"true\">Styled Markup for red color text with underscore in Text Field Expression</style>"+"  This is normal text "+"\n"+"no later than the following date: "+"<style forecolor=\"red\">This text is in red color without underscore</style>"]]></textFieldExpression>
			</textField>
		</band>
	</summary>
</jasperReport>

1 comment:

  1. you can use html in text field style if you want to use your given example

    ReplyDelete