Expression to change specific value text color in string of values in SSRS based on another field

自古美人都是妖i 提交于 2019-12-12 13:51:54

问题


I have a field in my SSRS report, that contains a string of numbers delimited with commas (from a coalesce select in SQL). It looks like 12, 91, 160, 171, 223. I would like to change the text color of only ONE specific value (160 for example) in the field, IF the value is also in another field of the report.

I already have this for an expression for the Font of the field properties.

=iif(Fields!Store_Number.Value.ToString().Contains (Fields!DMHomeStore.Value)= True,"Red","Black")

This changes the text color of the entire field, not just that ONE value in the string.

Basically, if DMHomeStore = 160, and Store_Number has 160 in it's string, then make only 160 Red in the Store_Number string.


回答1:


This can certainly be done and isn't difficult to do.

  1. Start with an empty table cell.
  2. Double click on the cell -> Right-Click -> Create Placeholder
  3. On the General tab, Value -> select the field that will contain the string of numbers
  4. On the same General tab, select "HTML, interpret HTML tags as styles
  5. Click OK

That's the first step. Now, all we need to do is set up an expression that will find the string in question and then replace it with HTML code to make it red.

  1. Right-click on the cell -> Select Expression
  2. Enter the following expression:
=Replace(Fields!Store_Number.Value.ToString(),Fields!DMHomeStore.Value," `<span style='color:red'>` " & Fields!DMHomeStore.Value & "`</span>`")

Run your report and only the string in question will be red and all other text in the cell will be black. If the string in question isn't found then all other text will be black.




回答2:


SSRS will not render all html tags, for example styling will get dropped from span tags. Heres a good reference http://dinesql.blogspot.com/2010/05/reporting-services-2008-showing-html.html



来源:https://stackoverflow.com/questions/3322088/expression-to-change-specific-value-text-color-in-string-of-values-in-ssrs-based

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!