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 have 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.

26 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
  15. Hello!

    I tried so many time, but I don't know why it is not working.
    I'm using SSRS 2008.

    ReplyDelete
  16. Hi. I want to set up my column width auto size. For exemple: In first page of my report I had in column1 same dates, and the second page my dates on column1 are larger then in first page. The column width size doesn´t grow up according the text size. Are you understanding me? I´m sorry about my english, it´s not perfect to explain things. Can somebody help meh? Thanks a lot

    ReplyDelete
  17. Thansk for your help, i was looking for this answer for a long time and found here.

    ReplyDelete
  18. Works great, but I lose my cell number formatting. Any thoughts how I can preserve that?

    ReplyDelete
  19. Got it to work with just text. How would I do this when my rows contain images

    ReplyDelete
  20. It did not work for me.. can you explain step by step to auto size width of column in SSRS

    ReplyDelete
  21. its not wrking for me..can u please say me the step

    ReplyDelete
  22. Excellent! Thank you very much.

    ReplyDelete
  23. It worked for me when I changed CanGrow set to "false" in the properties after following your instructions.
    Thank you.

    ReplyDelete
  24. 2008r2 Not working :(

    ReplyDelete
  25. Hi
    It didn't worked for me but if in the properties of the textbox you untick "sizing options" (in General area) this workaround works like a charm.

    ReplyDelete
  26. I tried this, no success. I am using expressions in an ssrs tablix. Now, the tablix header row just has straight text, no expression or field, as it contains the title of each column. Do I need to do anything special for that? jamarante@ciginsurance.com

    ReplyDelete