Friday, May 29, 2009

SSRS Column Width Auto Size

While fixing the problem described in my previous post I saw lots of people trying to set auto width for the columns. Without any luck though... I found a way:

  1. Change Expression to be something like =”<DIV>” & Replace(Fields!YourField.Value," ","&nbsp;") & “</DIV>”
  2. Change placeholder properties – General tab – Markup type – HTML-Interpret HTML tags as styles. (Placeholder properties can be accessed by right clicking on Expression (Field) inside of the cell, not on cell itself).

That was too easy :)

PS. Works for SSRS 2008, never tested on 2005.

PPS. Keep in mind - this works ONLY in web browser. Export to PDF and even printing will still use predesigned column width. There might be a workaround too - but I don't really need it, so I will leave it to you guys.

Please comment if you find any additional notes.

14 comments:

  1. Where did you insert this expression? I tried horizontal alignment under "Texbox Properties" and under size in the Properties pane. Neither worked.

    fzlala@gmail.com
    ReplyDelete
  2. I changed the value field in placeholder properties and replaced it with the provided expression. I also did step 2. It didn't work :(
    ReplyDelete
  3. Right click on the Field, then select "Expression" from the popup menu.
    ReplyDelete
  4. Amazing! never thought of that. Thank you for this tip. Helped save a lot of time!
    ReplyDelete
  5. I did all this and tried different ways but it doesn't work. I use RS 2008. nay ideas why?
    tautvis@gmail.com
    ReplyDelete
  6. It was working with SSRS2008. Double check all the steps and play with columns properties. For the test - create project from scratch just to test this functionality.
    ReplyDelete
  7. Cant find step 2 in SSRS 2005
    ReplyDelete
  8. It was never tested in SSRS 2005 so please comment if you were able to make it work.
    ReplyDelete
  9. I followed the steps in SSRS 2008 R2 and it did not work while viewing the report in IE 8.
    ReplyDelete
  10. Works well for me - thanks dude, Now to work out a way (other than basing column widths on parameters) to make it work for pdf's :/
    ReplyDelete
  11. This will not work in ssrs 2005 as it does not support html formatting. ssrs 2008 does.
    ReplyDelete
  12. Aw, this was a really quality post. In theory I'd like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.
    ReplyDelete
  13. In my case the bold formatting was preserved in both screen view and export formats (tried pdf and excel only). :)
    ReplyDelete
  14. it works just fine...thanks alot.
    ReplyDelete