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.

Wednesday, May 27, 2009

SSRS Column Width Long Text Problem

Recently I got a weird problem building some reports with SSRS 2008. The column width started to automatically resize based on content, while all columns width are fixed in SSRS by design. The cause of this was long words and long URLs in these fields, which were not able to wrap. Looks like HTML table was adjusting the column size accordingly. (By the way, it was still showing Ok in preview, but was changing the size of columns in published version.) Spent quite a time trying to figure out what to do with that, cause I need those column widths to be static. Here is the solution:

While this problem is caused by native HTML functionality, we can use HTML to fix it.

  1. Change Expression to be something like =”<DIV style=’width:1.2in’>” & Fields!YourField.Value & “</DIV>” where width is the desired static width of this column.
  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).

PS. I am also sure that you can use the same approach to create columns with adjustable or auto width, it just needs some tweaking. Update: Here it is.