Hi everyone, by means of introduction my name is Martin Vassilev and I am a support officer with the Windows Forms team here at Telerik. As of late, we noticed increased interest towards RadGridView data export capabilities.
What we have always told our customers is that the RadGridView will have only basic Microsoft Excel export capability, until we are able to implement a commercial grade format converter here at Telerik. However, that requires quite some time, and customers can’t wait right? What was needed was a quick, easy, stable way of exporting RadGridView content to formats such as RTF, PDF and XLS. We also wanted to leverage an existing technology, rather than start from scratch. Well - guess what: the answer turned out to be right next door (quite literally too) – Telerik Reporting.
For one, it already offers all the exporting capabilities we need, and also delivers a fine-grained and professional printing mechanism, with print preview capability and numerous adjustments options.
We have prepared a classhelper library that can be used to interface the RadGridView component with Telerik Reporting. Using the helpers allows the generation of flat (no hierarchy support at this moment) grids with or without grouping into a report that can easily be printed or exported to a number of formats.
What’s really neat is that when you create reports from RadGridView, most of its visual settings such as column widths, header colors, text alignments and font formatting are transferred to the report.
So, how do you use the RadGridReporting class and start creating your own reports based on RadGridView? Just add a copy of RadGridReportinLite.dll and add a reference to it in your project. To benefit from this functionality , you need to have installed both Telerik RadControls for Windows Forms and Telerik Reporting products. After that, you will be able to create an instance of ReportForm and set various options such as:
Property | Description |
RadGridReport.FitToPageSize | Fit column sizes to printing page |
RadGridReport.UseGridColors | Use grid header colors(mixed from gradients) |
RadGridReport.AllMargins | Set all page margins in milimeters |
RadGridReport.PaperKind | Choose report paper kind format (A4, A3 etc.) |
RadGridReport.PageLandScape | Choose lanscape or portrait view |
RadGridReport.RepeatTableHeader | Choose to repeate table header on every page |
RadGridReport.ReportWindowState | Windows state of report form |
RadGridReport.ReportSize | Size of report form (if not maximized) |
To generate the report, you need to call the ReportFormShow method and pass your RadGridView instance as a second parameter.
I have prepared a small Example application to illustrate the approach. It is available in our code library section.
I encourage you to experiment with it, and to add export and printing capability to your application. Please keep the feedback coming, and share with us how you would like to see this functionality extended in the future.Nikolay Diyanov Diyanov is the Product Manager of the Native Mobile UI division at Progress. Delivering outstanding solutions that make developers' lives easier is his passion and the biggest reward in his work. In his spare time, Nikolay enjoys travelling around the world, hiking, sun-bathing and kite-surfing.
Find him on Twitter @n_diyanov or on LinkedIn.