在SSRS-2008

时间:2018-03-07 13:57:59

标签: reporting-services ssrs-2008 ssrs-2008-r2

我有这个来自db的字符串,并且单词用空格分隔。单词的数量可以从最小的一个到最多的六个不同,所以我基本上想要的是在第二个单词之后立即开始一个新行。 例如,字符串“Natural Financial Services”需要显示为:expected result 在报告中。我的情况如果只有一个单词然后不应该有任何换行符,我已经尝试了这个Replace(Fields!CustodianNameTxt.Value," ",Vbcrlf)但这会导致字符串的每个单词出现在一个单独的行中,如下所示:result with my current expression 这不是预期的,有人请建议是否有任何解决方案来实现这一目标? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

可以做的一种方法是将字符串拆分为单词数组,然后使用选择函数使用添加的CRLF重建它 在这个例子中,选择是在一个isnothing里面,以满足少于六个单词的行:

=IIF(not isnothing(choose(1,split(Fields!CustodianNameTxt.Value," ")))," " + choose(1,split(Fields!CustodianNameTxt.Value," ")),"") 
+IIF(not isnothing(choose(2,split(Fields!CustodianNameTxt.Value," ")))," " + choose(2,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"") 
+IIF(not isnothing(choose(3,split(Fields!CustodianNameTxt.Value," ")))," " + choose(3,split(Fields!CustodianNameTxt.Value," ")),"") 
+IIF(not isnothing(choose(4,split(Fields!CustodianNameTxt.Value," ")))," " + choose(4,split(Fields!CustodianNameTxt.Value," ")) + Vbcrlf,"") 
+IIF(not isnothing(choose(5,split(Fields!CustodianNameTxt.Value," ")))," " + choose(5,split(Fields!CustodianNameTxt.Value," ")),"") 
+IIF(not isnothing(choose(6,split(Fields!CustodianNameTxt.Value," ")))," " + choose(6,split(Fields!CustodianNameTxt.Value," ")),"") 

答案 1 :(得分:0)

选择报告属性 - >代码

添加此功能(可能有更好的方法在VB中实现相同的功能,这只是一个例子):

Public Function splitline(byval line as string) as string   

dim words() as string=line.split(" ") ' separate the lines into array of words
dim pos as integer ' to calculate the position for the breaks
dim newlines as string = line ' string for the line with added breaks

if words.length > 2 then  ' there are 3 or more words add break after second word
    pos=len(words(0)) + len(words(1)) + 1 ' this will be the position of the first break
    newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if

if words.length > 4 then  ' there are 5 or more words add break after forth word
    pos=len(words(0)) + len(words(1)) + len(words(2)) + len(words(3)) + 4 ' adding 4 because 2 spaces + cr + lf
    newlines=newlines.remove(pos,1).insert(pos,VBCRLF) ' remove the space and add a break
end if  

return newlines

End Function

遗嘱中的表达式就是:

Code.splitline(Fields!CustodianNameTxt.Value)