Subscribe to Cache Cow        RSS Feed
-----

Maintain Datatype When Exporting RDLC Report to Excel

Icon Leave Comment
If you are like me, you have to use the Reportviewer object quite often in your .NET development. If that is the case, you have also found that there isn't a whole lot of help out there with reference to said reports.

The other day, a customer asked me to write a small application for him which would compile a bunch of information in a report. He would then use the built in feature of the Reportviewer to export the report to Excel for processing via another third party program. The problem was that when he went to use the Excel file, some of the columns had been translated into text fields instead of numeric fields like it was in the report. You will notice that any of the data bound fields which come from your datatable directly will stay the proper data type, its when you try to do calculations that it dumps the data type. For example: "=iif(a = b, 0, a)". I perused the internet trying to find a solution, but had no luck. I did, however, find a site that gave me an idea of how to ensure a columns values get translated as the proper data type. You will find pictures of the steps below:

Step 1: Create your report.
Attached Image
Nothing exciting here. You will note that I have most of the fields filled directly from my dataset, not from a modified expression.

Step 2: Find the rdlc file in the solution explorer of Visual Studio (I am using 2010)
Step 3: Right click the rdlc report and click "Open With" then pick XML (Text) Editor
Attached Image
Attached Image

Step 4: Insert the line "<rd:TypeName>System.Decimal</rd:TypeName>" into your XML code at the correct spots (pic below).
Attached Image
So, you find the expression you want to ensure saves as a certain data type (Integer, Double, etc.). You then go into the TablixCell block and add the code (see picture of mine). That's it. Pretty simple. I will add a disclaimer that I, in no way, am making a guarantee that this will work for you, but it did work for me. As of right now, it hasn't caused any noticeable issues.

Step 5: Save the report...

I hope this little tidbit of info was helpful.

On a side note, I have noticed a complete lack of interest in supporting the Reportviewer specifically. There are several bugs I have noticed with using it and there isn't a whole lot of documentation on how to modify or use certain features of this object. I posted a question a very long time ago in the MSDN forums on the RDLC report and it has yet to be answered.

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

December 2014

S M T W T F S
 123456
78910111213
14151617 18 1920
21222324252627
28293031