Dynamically change the font size of a single character in SSRS

Jay C picture Jay C · Feb 7, 2015 · Viewed 7.1k times · Source

Using SSRS in Visual Studio 2012 I currently have the following expression in the report header.

=ReportItems!FirmName.Value

This correctly pulls the Firm name such as Client1, Client2, Client3 etc... from the body of the report.

However if ReportItems!FirmID = 600, I need the Font size of the first character in Firm name to be larger then the other characters.

This is because a particular client has a logo where the first character is larger than the others.

I tried the following expression which I know is wrong but might illustrate what I'm trying to do.

=IIF(ReportItems!FirmID.Value = 600,LEFT(ReportItems!FirmName.Value,1), "18pt", ReportItems!FirmName.Value))

So say client3 has FirmID 600 the result should be like this, you may need to run the code snippet to see what I mean...

I tried Ian's suggestion

which I thought was working, but I cannot yet get it to work. I can get this to work in the report body, but there are additional complications. The font size change needs to be in the Report Header, which requires referencing the report body via ReportItems! You cannot reference more than one ReportItems! in the report header or you get an error like the following

The Value Expression for the textrun Textbox12 refers to more than one report item. An expression in a page header or footer can refer to only one report item.

Yet there is one more problem and I should have clarified this in my original entry. The actual client name is like this.

Client & Associates

Both of the first letters need to be larger, but not the ampersand between them.

<html>

<body lang=EN-US style='tab-interval:.5in'>

<div class=WordSection1>

<p class=MsoNormal><span style='font-size:22.0pt;line-height:115%'>C</span>lient
&amp; <span style='font-size:18.0pt;line-height:115%'>A</span>ssociates</p>

</div>

</body>

</html>

Answer

Ian Preston picture Ian Preston · Feb 9, 2015

You can do this by creating a couple of text placeholders within the same textbox, splitting the text between these and apply a font-size expression to the first placeholder only.

See Formatting Text and Placeholders for a good overview.

In a simple example with your data:

enter image description here

I have a simple table to display this:

enter image description here

Note there are two <<Expr>> values in the last column - I have added another placeholder in this textbox.

I have split FirmName between these placeholders; in the first:

=Left(Fields!FirmName.Value, 1)

and in the second:

=Right(Fields!FirmName.Value, Len(Fields!FirmName.Value) - 1)

Even though the text is split in two expressions, it looks fine when the report is run:

enter image description here

Since each placeholder can have its own formatting, we can apply an expression like the following to FontSize on the first placeholder only:

=IIf(Fields!FirmID.Value = 600, "15pt", "10pt")

i.e. increase font size of the first letter for firm 600, which gives us the required results:

enter image description here