SSRS – Reports dont fit in Word Export

Well its been a long time blogging and as Title suggest I have been putting quite some time in past few months on SSRS reporting, and came up with an interesting challenge to blog about.

Recently I was mocking up a SSRS report where suddenly business users (testing the same) came up with a query that the reports rendered fine on the UI (SSRS Viewer) but when they would export it out to the MS-Word format the report would render quite out of sync in terms of page width and content over-flows.

And eventually with all my efforts of getting it in shape with all page margins, page width and other page layout orientation, the report would often break apart into other pages and hardly fitting in within the borders no matter the effort.

So finally coming down to the magic solution for the same was breaking the wide strings as they rendered on the report with the line breaks “vbCrLf” (i.e. VB code for line break) using custom function in SSRS.


Function LineBreaks(strVal as String, charNo as Int32) AS String
	Dim slen as Int32
	Dim rStr as String
	Dim iCount as Int32
	slen = strVal.Length
	iCount = 1
	while iCount <= slen
		rStr = rStr +Mid(strVal ,iCount, charNo) + vbcrlf
		iCount  = iCount + charNo
	End While
	rStr = rStr +Mid(strVal ,iCount, charNo)
	Return rStr
End Function

And using the above code in the text box expressions of Table/Matrix as:

= Code.LineBreaks(Fields!FieldName.Value, Variables!MaxLengthOfLine.Value)

Now in some cases this may not be essential, but in my instance with all the head scratching this code was a life saver. So as for few who are stuck in similar situation, feel free to leverage the above.

Hope it helps !!!

Posted in Uncategorized

One Reply to “SSRS – Reports dont fit in Word Export”

  1. Thanks pretty old post, but, saved my day. Have no skills at VB, but added a check to code, to find last space to not split words in a middle.

Leave a Reply

Your email address will not be published. Required fields are marked *