简体   繁体   English

SSRS 表达式中的换行符

[英]Line break in SSRS expression

I'm having trouble adding a line break in SSRS 2008.我在 SSRS 2008 中添加换行符时遇到问题。

I've tried all of these different ways but nothing is doing it.我已经尝试了所有这些不同的方法,但没有任何效果。

"+ chr(10) +" , "& chr(10) &" , "& chr(13) & chr(10) &" , "& vbcrlf &" , "+ vbcrlf +" , "Environment.NewLine"

Here's my textbox expression:这是我的textbox表达式:

=IIF(First(Fields!VCHTYPE.Value, "Dataset1")="C","This is a huge paragrpah of text." +
vbcrlf + "separated by line feeds at each paragraph." +
vbcrlf + vbcrlf + "I want to separate the paragraphs." +
vbcrlf + vbcrlf + "Its not working though."
, "This is the second huge paragraph of text." +
vbcrlf + "separated by line feeds at each paragraph." +
vbcrlf + vbcrlf + "I want to separate the paragraphs." +
vbcrlf + vbcrlf + "Its not working though." )

使用Environment.NewLine而不是 vbcrlf

如果您的占位符处于启用 html 的模式,则"<br />"将用作换行符

This works for me:这对我有用:

(In Visual Studio) (在 Visual Studio 中)

  1. Open the .rdl file in Designer (right-click on file in Solution Explorer > View Designer)在设计器中打开 .rdl 文件(右键单击解决方案资源管理器中的文件 > 查看设计器)
  2. Right-click on the Textbox you are working with, choose Expression右键单击您正在使用的文本框,选择表达式
  3. In the Set expression for: Value box enter your expression like:Set expression for: Value框中输入您的表达式,例如:

     ="first line of text. Param1 value: " & Parameters!Param1.Value & Environment.NewLine() & "second line of text. Field value: " & Fields!Field1.Value & Environment.NewLine() & "third line of text."

You should NOT quote your Environment.NewLine man.你不应该引用你的 Environment.NewLine 人。 Try "Your Text" & Environment.NewLine .试试"Your Text" & Environment.NewLine

In Order to implement Line Break in SSRS, there are 2 ways为了在 SSRS 中实现 Line Break,有 2 种方式

  1. Setting HTML Markup Type设置 HTML 标记类型
    Update the Markup Type of the placeholder to HTML and then make use of <br/> tag to introduce line break within the expression将占位符的标记类型更新为 HTML,然后使用<br/>标签在表达式中引入换行符

="first line of text. Param1 value: " & Parameters!Param1.Value & "<br/>" & Parameters!Param1.Value

  1. Using Newline function使用换行功能
    Make use of Environment.NewLine() function to add line break within the expression.利用 Environment.NewLine() 函数在表达式中添加换行符。

="first line of text. Param1 value: " & Parameters!Param1.Value & Environment.NewLine() & Parameters!Param1.Value

Note:- Always remember to leave a space after every "&" (ampersand) in order to evaluate the expression properly注意:-始终记住在每个“&” 与号之后留一个空格,以便正确评估表达式

Use the vbcrlf for new line in SSSR.在 SSSR 中使用vbcrlf作为新行。 eg例如

= First(Fields!SAPName.Value, "DataSet1") & vbcrlf & First(Fields!SAPStreet.Value, "DataSet1") & vbcrlf & First(Fields!SAPCityPostal.Value, "DataSet1") & vbcrlf & First(Fields!SAPCountry.Value, "DataSet1") 

I've always had luck with the Chr(10) & Chr(13) - I have provided a sample below.我一直很喜欢 Chr(10) 和 Chr(13) - 我在下面提供了一个样本。 This is an expression for an address text box I have in a report.这是我在报告中的地址文本框的表达式。

=Iif(Fields!GUAR_STREET_2.Value <> "",Fields!GUAR_STREET.Value & Chr(10) & Chr(13) & LTrim(Fields!GUAR_STREET_2.Value),Fields!GUAR_STREET.Value)

Also, if you are building a string you need to concatenate stuff together with an & not a + Here is what I think your example should look like此外,如果您正在构建一个字符串,则需要将内容与 & 而不是 + 连接在一起,这是我认为您的示例应该是这样的

    =IIF(First(Fields!VCHTYPE.Value, "Dataset1")="C","This is a huge paragrpah of text." &
Chr(10) & Chr(13) & "separated by line feeds at each paragraph." &
Chr(10) & Chr(13) & Chr(10) & Chr(13) & "I want to separate the paragraphs." &
Chr(10) & Chr(13) &  Chr(10) & Chr(13) & "Its not working though."
, "This is the second huge paragraph of text." &
Chr(10) & Chr(13) & "separated by line feeds at each paragraph." &
Chr(10) & Chr(13) & Chr(10) & Chr(13) & "I want to separate the paragraphs." &
Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Its not working though." )

It wasn't working for me either.它也不适合我。 vbcrlf and Environment.Newline() both had no effect. vbcrlf 和 Environment.Newline() 都没有效果。 My problem was that the Placeholder Properties had a Markup type of HTML.我的问题是占位符属性具有 HTML 的标记类型。 When I changed it to None, it worked like a champ!当我将其更改为 None 时,它​​就像一个冠军!

你可以用这个

="Line 1" & "<br>" & "Line 2"

In my case, Environment.NewLine was working fine while previewing the report in Visual Studio.就我而言,在 Visual Studio 中预览报告时 Environment.NewLine 工作正常。 But when I tried to publish the rdl to Dynamics 365 CE, I received the error "The report server has RDLSandboxing enabled and the Value expression for the text box 'Textbox10' contains a reference to a type, namespace, or member 'Environment' that is not allowed."但是,当我尝试将 rdl 发布到 Dynamics 365 CE 时,收到错误“报表服务器启用了 RDLSandboxing,并且文本框‘Textbox10’的值表达式包含对类型、命名空间或成员‘环境’的引用不被允许。”

So I had to replace Environment.NewLine with vbcrlf.所以我不得不用 vbcrlf 替换 Environment.NewLine。

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

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