Textbox Formatting In SSRS 2008 - Break Line

巧了我就是萌 提交于 2019-12-10 15:05:34

问题


So, say I have the following string

THIS IS STUFF (MORE STUFF)

How would I get the string to format as such in a textbox in SSRS?

THIS IS STUFF
(MORE STUFF)

This data is pulled from a single field in a query and I will not be able to manually inject a break line.

Also, sometimes the (More Stuff) is not in the field.

Extra examples:

  • STUFF AND THINGS
  • THINGS (STUFF)
  • THINGS AND STUFF (MORE STUFF)

  • 回答1:


    You need to insert a line break into the string, i.e. set the textbox expression as something like:

    ="THIS IS STUFF" & vbcrlf & "(MORE STUFF)"
    

    So the expression in a single textbox:

    Will render as:

    You can see there is a line break even though the string could fit on one line.

    Edit after comment

    OK, we need to handle various existing strings at the report level.

    To do this, I would suggest using Custom Code, i.e. a function like:

    Function SplitString (fieldValue As String) As String
      If IsDBNull(fieldValue) OrElse IsNothing(fieldValue) Then
        SplitString = ""
      Else If InStr(fieldValue, "(") > 0
        SplitString = RTrim(Left(fieldValue, InStr(fieldValue, "(") - 1)) & _
          vbcrlf & Right(fieldValue, Len(fieldValue) - InStr(fieldValue, "(") + 1)
      Else
        SplitString = fieldValue
      End If
    End Function
    

    I'm suggesting this as SSRS expression are notoriously brittle, and the lack of short circuiting means that what works for one string might display #Error on another. You could get around this with numerous IIf statements but Custom Code is much neater and easier to understand.

    You can call the function with an expression like:

    =Code.SplitString(Fields!MYFIELD.Value)
    

    Either in a textbox expression or as a Calculated Field in the Dataset. The above works for me on your data:




    回答2:


    I came across this issue while doing my project. And I would like to share my steps for this. Create individual placehloders within the textbox by selecting the expression and format each as you desired. You can easily add extra line by just moving the another item(another placeholder) to next line(by pressing enter-on the keyboard) Here I created individual placeholders inside the list, gave the names and format just as I want.



    来源:https://stackoverflow.com/questions/19141650/textbox-formatting-in-ssrs-2008-break-line

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