Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

SQL Reporting Service Superscript issue

1.57/5 (4 votes)
4 Mar 2008CPOL3 min read 1   223  
Superscripts in SQL Reporting Services.

Introduction

SQL Server Reporting Services is widely used for generating reports or large numbers of letters. Letters or Reports that are generated used SQL Server Reporting Services might need different styling like italics, suprescript etc. according to the business needs. There are might be several solutions for this problem but the approach i suggest in this article is fast and effective to implement.<o:p>

Background

What usually people do for situations like this will be using a textbox with a smaller font and align the text to top. Though this looks like a good enough solution but fails in many cases. This solution will be effective for a case where there are no dynamic texts coming along with the Superscript. But consider the case where a dynamic text comes from the DB, then in this case with the change in the length of the incoming text the positioning of the Superscript textbox will be a problem and will disturb the complete layout of the report. So this solution will be helpfull in those cases. To solve this problem we will generate an image at runtime and embed it in the report.<o:p>

For example, consider the case where the following text appears as a row in the report designer.

{Name of Employee}'s coverage with {CompanyName}(superscript} has ended as of {Date}


sample:
aaa's coverage with ABC pvt Ltd "TM" has ended as of 10/01/2008

Note: Here TM is indicated in double quotes to identify that it is a superscript.

Now, in this case we are not sure about the length of the Employee's Name so we cannot position the superscript "TM" effectively.This is the problem we faced in our organization while generating a similar report. We tried a lot of options and the worst case being hardcoding the employee's name. So a solution was badly needed for this problem. Thus we arrived at this solution.

Solution

Pass on the text to a class library which will generate an image out of the text and will return the result in bytes format. Now assign the bytes to image control's value property in the report designer.

Description

Once you download the zip file, build it once and generate the dll. This generated dll has to be placed in the following places.

1. C:\Program Files\Microsoft SQL Server\MSSQL.1\Reporting Services\ReportServer\bin
This is the Path where the SQL Server is installed

2. C:\Program Files\Microsoft SQL Server\MSSQL${MACHINE-NAMES}QLSVR\Binn
This is the Path where MSSQL machine name binn is installed

Use of Code

We are half way through with these steps.


Now adding the following code to the Code property of the Report Properties window will take us to the solution.

Public Function getImage(ByVal empName as String, ByVal DOJ as String) As Byte()
  Dim str As System.IO.MemoryStream = New System.IO.MemoryStream
  str = obj.generateImage(EmpName,DOJ) 
  return str.ToArray()
End Function

//The Text position, Font size, font family and few other attributes are done in the dll. 
//This can be made generic by moving these attributes to the above described function.

Things to Remember

Once you are done with these things, we are just one step away from finishing the task. Add the following code to the value property for the image control in the report designer.

=Code.getImage(Fields!EmployeeName.Value,Fields!DOJ.Value)

Once the above step is done. Please do the following.

To the references tab of the Report Properties under Report add the following under references

1. System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

2. System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

3. RunTimeImageGenerator

then under the classes section create an object for the ImageGenerator Class.

Give "ImageGenerator" as Class Name and "obj" as Instance name

Conclusion

By this, we will be generating the image with dynamic text. Hope this will be useful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)