How to display Line Breaks and Tabs in SSRS

This question has suggested answer(s)

I am trying to bring the SY03900.txtfield onto a SSRS report.  I would like to preserve both the line breaks and the tabs that have been entered in GP. 

I am using the following to preserve line breaks 

 

=REPLACE(Fields!txtfield.Value,chr(13),vbCrLf)  

(this formula is from a newsletter from Victoria Yudin's Flexible Solutions.)

 

How can I change this formula to also preserve the tabs (ie when the user inputting the data hits the tab key)?

Thank you.

All Replies
  • Robyn,

    Thanks for subscribing to our newsletter!  We have experimented with various options for tabs, however, have not found anything that works correctly or consistently.  :-(

  • Even after reading Victoria's comment, try

    =Replace(fieldstxtfield.Value,chr(8),"        ")

    Richard L. Whaley Author, Publisher, Consultant

    http://www.AccoladePublications.com

    Enhancing your Dynamics Knowledge!

  • Thanks for the replies.

     

    I have tried the following:

    1)  =replace(replace(Fields!txtfield.Value,chr(13),vbCrLf),chr(9),vbTab)

     

    vbTab does not seem to work at all.

     

     

    2)  =replace(replace(Fields!txtfield.Value,chr(13),vbCrLf),chr(9),SPACE(4))

    3)  =replace(replace(Fields!txtfield.Value,chr(13),vbCrLf),chr(9),”    “)

     

    2 and 3 work sufficiently in Visual Studio and when exported to Excel and PDF, but in Report Manager the four spaces are reduced to a single space.

     

    I'm not sure, but I’m guessing that HTML treats whitespace differently.

  • Yes you are correct HTML will reduce multiple spaces to a single space. The code to add a space that will not be trimmed off is:  . So in your case to get the spaces you need:

    =replace(replace(Fields!txtfield.Value,chr(13),vbCrLf),chr(9),”    “)

    This however will probably print on the Excel and PDF exports.

    Scott

  • Hi Scott,

    Thanks for your reply.  

    Can you please tell me again what is the code to add spaces that will not be trimmed in HTML?  To me it looks like you have typed some spaces between quotes, but I already tried this and it gets trimmed.  Are they different types of quotes?

    Thanks!

  • In HTML you have to use a non-breaking space which is character code 160. To replace a tab with 4 non-breaking spaces you would use something like this:

    =Replace(Fields!txtfield.Value, Convert.ToChar(9), New String(Convert.ToChar(160), 4))

    Keep in mind that this may look and act like a space but it's not. As an example, if you insert a non-breaking space between "Bob" and "Smith" you would not be able to find this if you exported to excel and searched for "Bob Smith".

  • jgv, thanks for posting this.  I have been searching for a solution to this for some time.

    The following is working for us:

    =Replace(Replace(Fields!txtfield.Value,chr(13),vbCrLf),Convert.ToChar(9), New String(Convert.ToChar(160), 4))  

    Many thanks to everyone for responding.