简体   繁体   English

SSRS表达式-值昏迷后换行/换行

[英]SSRS Expression - Line break/new line after coma in value

One of the textbox contains a comma separated set of values as displayed below, 其中一个文本框包含一组用逗号分隔的值,如下所示,

1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,1234

Existing output: 现有输出:

1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,123  
4,1234,1234,1234,1234

Expected output: 预期产量:

1234,1234,1234,1234,1234,1234,1234,1234,1234,1234,
1234,1234,1234,1234,1234

Line should only break after coma value rather than breaking the value 1234 行仅应在昏迷值之后中断,而不是中断值1234

I am looking for an expression to achieve that. 我正在寻找一种表达方式来实现这一目标。 Changing textbox size is not in scope. 更改文本框大小不在范围内。

I am fairly confident that what you want is not possible without assuming that the values between the commas will always be the same length. 我非常有信心,如果不假设逗号之间的值始终是相同的长度,就不可能实现所需的内容。

Your text is breaking in the 'middle' of a value because SSRS does not know that your commas should be treated as breaking characters, like it would a space . 您的文本在值的“中间”中中断,因为SSRS不知道您的逗号应被视为断字符,就像space

As a result, your options are limited and depend on what the purpose of this textbox is. 因此,您的选择受到限制,并且取决于此文本框的用途。 If you just want to display the data, then you can worry less about how the break is defined but if you need to use this data elsewhere you do need to worry. 如果只想显示数据,则可以不必担心中断的定义方式,但是如果需要在其他地方使用此数据, 不必担心。

If you need to use the data elsewhere via copy and paste and you absolutely can't have the spaces you're mostly out of luck. 如果您需要通过复制和粘贴在其他地方使用数据,而您绝对不能拥有大部分靠运气的空间。 If you don't have to copy the data anywhere you have two options you can simply add spaces after your commas to get the breaks you want in the report: 如果您不必在任何地方复制数据,则有两个选择,您只需在逗号后添加空格即可在报告中获得所需的休息时间:

Option 1 - Visible Space Character 选项1-可见空间字符

Use replace to swap all comma characters with a comma and a space which will show up on the report. 使用replace将所有逗号字符替换为逗号和一个空格,该空格将出现在报告中。 Whilst this may not be aesthetically desirable, at least it is obvious what is happening in the report, unlike option 2... 尽管从美学上可能不希望这样做,但至少与选项2不同,很明显报告中正在发生什么...

=replace(Fields!YourCol.Value, ",", ", ")

Option 2 - Non-Visible Space Character 选项2-不可见的空格字符

Use replace again, but swap the comma with a comma and a Zero-Width Space character. 再次使用replace ,但用逗号和零宽度空格字符交换逗号。 Whilst in the report design this will be apparent, anyone trying to copy the data may get issues as there are characters present that cannot be seen. 尽管在报表设计中这是显而易见的,但是尝试复制数据的任何人都可能会遇到问题,因为存在无法看到的字符。 You can see this by selecting the text he​re . 您可以通过选择是的文本来查看。 As you hold shift and move left and right using the arrow keys, you will notice that you need an extra press to get between he and re . 按住shift键并使用箭头键左右移动时,您会发现需要额外按一下以在here之间移动。

The unicode character number you need for this is 8203 , which you can use with the ChrW ssrs function: 为此所需的Unicode字符编号是8203 ,可以将其与ChrW ssrs函数一起使用:

=replace(Fields!YourCol.Value, ",", "," & chrw(8203))

Another way of doing it is via a function that splits the line into and array of words and then rearrange the words in lines of a predefined size. 做到这一点的另一种方法是通过一个函数,将行分为单词数组和单词数组,然后将单词重新排列为预定大小的行。

This function accepts two parameters, the line to split and the max size and returns a new line broken to not exceed the max size and without breaking the words. 此函数接受两个参数,即要拆分的行和最大大小,并返回折断为不超过最大大小且不折断单词的新行。

Public Function splitlineaftercomma(byval line as string, linesize as integer) as string 公共函数splitlineaftercomma(以字符串分隔,以行大小,以整数表示),以字符串形式

dim words() as string=line.split(",") 
dim newlines() as string={""}
dim i as integer=0  
dim j as integer=0
for i=0 to words.length - 1
    if len(newline(j)+words(i)+",")>linesize then 'if the line is overflown create new line
        array.resize(newlines, newlines.length+1) 
        j+=1
    end if
    newlines(j)+=words(i)+"," 'add word plus comma to current line
next i
newlines(j)=newlines(j).trimend(",") ' remove last comma
return string.join(vbcrlf,newlines) 

End Function 结束功能

suppose your box has a size of 30 char then you can call the function as: 假设您的盒子的大小为30个字符,则可以将函数调用为:

=Code.splitlineaftercomma(linetosplit,30)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM