Documente Academic
Documente Profesional
Documente Cultură
Reports are used by business for various management purposes. Crystal reports is very versatile and easy to use reporting tool that is bundled with the Microsoft
Visual Studio .Net. There have been many enhancements in the latest version of crystal reports which make it simpler for developers to export reports directly to the
HTTP response object.
The export option is very useful when business users want to have reports exported different formats such as PDF, Excel, Word and HTML. They want this facility
in order to download the report and store it for future use or to modify the report further (possible in case of Word and Excel). In many cases the export option is
used for scheduled reports to be send via email, In this case, the exporting is done on the server side and the exported file is attached to an email and send to the
user's email id.
In this tutorial, I will be showing you how to export a report to PDF format, but it can be easily modified to export the report in other formats.
I will be using an XML file as the data source for this tutorial. In normal scenarios a business layer class would return a dataset or datatable containing data to be
displayed in the report. So I created an XML file with customer data and will be reading the contents into a Dataset.
Enter the name of the report, I used the default name given by the IDE.
When the Crystal report wizard comes up select "Standard" and click OK.
Expand the Create New Connection node and then expand the ADO.net option.
Select all the columns that you need to display in the reports. I selected all of them for simplicity.
Setup grouping as needed to display the report.
The report is now created, you can now change the layout, add logos, etc.
Display the report on a web page
In the design view drag and drop the crystal reports viewer from Toolbox onto the web page.
<body>
<form id="form2" runat="server">
<div>
<asp:Button ID="btnShow" runat="server" OnClick="btnShow_Click" Text="Show Report in Viewer" /><br />
<br />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
Remember to add following namespaces at the top of code behind page for referencing Crystal Report objects.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
<body>
<form id="form2" runat="server">
<div>
<asp:Button ID="btnShow" runat="server" OnClick="btnShow_Click" Text="Show Report in Viewer" /><br />
<br />
<asp:Button ID="btnExport" runat="server" OnClick="btnExport_Click" Text="Export To PDF" />
<br />
<br />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
PDF ExportFormatType.PortableDocFormat
Complete
Report to ExportFormatType.Excel
Report to ExportFormatType.Excel
Excel
Only
Report
ExportFormatType.ExcelRecord
Data to
Excel
HTML ExportFormatType.HTML40
RTF ExportFormatType.RichText
Word ExportFormatType.WordForWindows
Once you click on the Export the PDF button the dialog box to download the pdf file will appear.
You can download Sample Export Crystal Report To PDF Visual Studio Project, used in this tutorial.
Many people found that Crystal Reports are complicate to learn. Personally, I like Stimulsoft Reports for ASP.NET application. If you use SQL Server, nice solution
is ApexSQL Report.
This tutorial is written by Chirag Nirmal - CANSoft.