SSRS Report - Control Your Data Length in a table column per column line

Published on
13,316 Points
1 Endorsement
Last Modified:
This code started out as a fix for a customer that had incoming data that was hunderds of numbers and words long that was to fit in one column. The problem was that the customer did not want to split words or numbers when wrapping in the column.

Ok the fun part was "how am I going to control the output to the column from the table? ". So the first thing I started working on was seeing how many characters would fit on a single line of the column that I need to use; and still look nice in the report.

Since the report had alot of data per detail row in the table I ended up with a column width length of 29 characters for this report. What was nice was that on this report the data was being split up by using a comma as a delimiter. Once the width was decided, the next step would be to wrap the incoming data so that each part of the data would wrap by design rather than arbitrary.

My favorite namespace in coding this type of data is using RegularExpressions; the use of RegularExpressions is only limited to your imagination. The code could be used with other applications. You would just have to experiment with it in the project that you are working on.

The code is pretty straight forward when you look at; just place the code in your report code tab properties. The delimiter can be just about any character you want. The sample uses the "comma" character as a delimiter. The InputString is the data that is coming in from you dataset; an example would be Trim(Fields!WordValues.Value) and the last field would be the width of your column. The sample below is using 29, meaning that the maxium number of characters on a single column row.

This is a sample of what the code would look like in the textbox or column cell of the table.


Open in new window

Sample out put would look something like this.....

Column A
 chars, long, the, length, of 
,970444, 77707,the, key, to, 
how, this, works

Open in new window

You will notice that the contents of "Column A" now wraps cleanly at a word or comma.

So, the only thing remaining is to show you the code for the FineDelimiter() function :

Public Function FineDelimiter(ByVal Delimiter As String, ByVal InputString As String, ByVal MaxLen As Integer) As String
        Dim FirstRow As Boolean = True
        Dim Counter As Integer = 0
        Dim MaxCnt As Integer = 0
        Dim strHolder As String = Nothing

        If InputString = Nothing Then Return Nothing

        For Each matchCurrent As String In  System.Text.RegularExpressions.Regex.Split(InputString, Delimiter)
            Counter += matchCurrent.Length + 1
            MaxCnt += matchCurrent.Length + 1
            If Counter > MaxLen Then
                FirstRow = False
                Counter = 0
            End If
            If FirstRow = True Then
                strHolder += matchCurrent + Delimiter
            ElseIf Counter = 0 Then
                If InputString.Length + 1 = MaxCnt Then
                    strHolder += vbNewline & matchCurrent
                    strHolder += vbNewline & matchCurrent + Delimiter
                End If
                Counter = matchCurrent.Length + 1
                If InputString.Length + 1 = MaxCnt Then
                    strHolder += matchCurrent
                    strHolder += matchCurrent + Delimiter
                End If
            End If
        Next matchCurrent

       If MaxCnt >= 2 And MaxCnt <= MaxLen Then
            Return strHolder.Substring(0, strHolder.Length - 1)
            Return strHolder
        End If
        Return Nothing
    End Function

Open in new window

The only other consideration is taking care when deciding your character count (width) depending on the type of font you are using, and once determined, dont change the font :)


Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Join & Write a Comment

There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month6 days, 8 hours left to enroll

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month