0

I want to add hyphenation to the column headers of a tablix

Consider the column value "waterbodiesinhereforme"

Currently SSRS is hyphenating based on the size it can fit inside the tablix column header.
Like below .

waterbodiesinh
ereforme

But my requirement is
waterbodiesin-
hereforme

So far I have tried the soft hyphen character , ­ which did not work in the ssrs even though html rendering was set to true. Even the Unicode "00AD" did not work.

When I tried with the ZeroWidthCharacter it worked correctly, but I do not know how to introduce a hyphen when there is a new line.

Zero Width Character Example ="water" + ChrW(&h200B) + "bodies" + ChrW(&h200B) + "in" + ChrW(&h200B) + "here" + ChrW(&h200B) + "for" + ChrW(&h200B) + "me"

Things I cannot do - Hardcode the hyphen (not acceptable because this value is dynamic)

ndavid9
  • 13
  • 3
  • How about using a code element in the report. This could break the string into an array where there are carriage returns. You could then use this array to add zerowidthcharacters after every "n" characters. – MiguelH Mar 12 '18 at 16:59
  • Do you mean split it based on the carriage return ? I just found out that that there is no carriage return when the text is wrapped. Could you please elaborate on the solution? – ndavid9 Mar 14 '18 at 11:27
  • https://stackoverflow.com/users/7467498/ndavid9 See below ... – MiguelH Mar 14 '18 at 14:41

1 Answers1

0

I've written this in Excel VBA, but this can be easily transferred to SSRS.

This splits the input string into parcels of 10 characters separated by carriage returns. You can change the string length by changing the initial value of IntSplit.

You could add your zerowidthcharacter if you wanted.

The Function code would need to be added to the "Report Properties>Code" section of the SSRS, with the string requiring the split being placed in the Expression for the field:

=code.SplitString(Fields!YourFieldName.value)

Here's the code ...

Private Sub do_it()
 Dim strString As String
 Dim StrNewString As String
    strString = "This is a very long sentence that needs to be chunked up"
    strString = SplitString(strString)
    Debug.Print strString
End Sub
Private Function SplitString(ByVal strInput As String) As String

Dim StrOut As String

Dim IntSplit As Integer
Dim Intstart As Integer
Dim j As Integer

IntSplit = 10
Intstart = 1
StrOut = ""

For j = 1 To Len(strInput)
    If Int(j / IntSplit) = j / IntSplit Then
        StrOut = StrOut + Mid(strInput, Intstart, IntSplit) + vbCrLf
       Intstart = j + 1
    End If
Next
StrOut = StrOut + Mid(strInput, Intstart, Len(strInput) - (Intstart - 1))
SplitString = StrOut
'Return SplitString ' A Return statement is required in SSRS
End Function

Output

This is a 
very long 
sentence t
hat needs 
to be chun
ked up
MiguelH
  • 1,415
  • 1
  • 18
  • 32