Showing posts with label Crystal Report. Show all posts
Showing posts with label Crystal Report. Show all posts

Tuesday, June 12, 2012

Asp.Net Export to PDF using Crystal Reports


In this post Asp.Net Export to PDF using Crystal Reports, we shall see on how to export the content of a Crystal report to a PDF file. 

Here we will use the report which we designed in the port Crystal Reports CrossTab Report in Asp.Net. To know more on the basics of how to create a Cross-tab report refer the post 
Crystal Reports CrossTab Report in Asp.Net.

All the procedures for designing the report, binding the data to the report will remain same as we saw in the post Crystal Reports CrossTab Report in Asp.Net. Here instead of displaying the report in the CrystalReportViewer, we will export the report as a PDF file.

Add the following lines of code before and after binding data to the CrystalReport

Before
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
HttpContext.Current.Response.ContentType = "application/pdf";
MemoryStream objStream;

After
objStream = (MemoryStream)objRptCrossTab.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(objStream.ToArray());


The complete code is as follows

HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
HttpContext.Current.Response.ContentType = "application/pdf";
MemoryStream objStream;

// Add Data access code to get the data into the Dataset dsCrossTab
objRptCrossTab = new rptCrossTab();
objRptCrossTab.SetDataSource(dsCrossTab);

// Export the Report to PDF
objStream = (MemoryStream)objRptCrossTab.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
//
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.BinaryWrite(objStream.ToArray());

Save and run the page, the File Download dialog will pop-up, you can save the PDF file to the disk by selecting the required location.

That's it we have exported a Crystal Report to PDF file using Asp.Net

Crystal Reports Crosstab Report Suppress Grand and Subtotals


In this post Crystal Reports Crosstab Report Suppress Grand and Subtotals, we shall see on how to suppress the Grand and Sub-Total values which come with the Cross Tab report.

To know more on how to create a Cross-tab report refer the post Crystal Reports CrossTab Report in Asp.Net.


A Crosstab report by default comes with Row and Column wise Grand and Subtotals
A Grand Total is added to all the Cross Tab reports
A Subtotal is added to Cross Tab reports, which have grouping enabled in Rows/Columns


In many cases we might not want the Grand and Sub totals, as they get embedded between the data and give a confusion, here we shall see on how to disable these.

To Disable Grand Totals
Right click on the Cross Tab and select Cross Tab Expert
Navigate to the Custom Style Tab
Check the Suppress Row/Column Grand Total checkboxes

Click OK

To Disable Sub Totals
Right click on the Cross Tab and select Cross Tab Expert
Navigate to the Custom Style Tab
Under Rows/Columns select the Field which is used for Grouping
Under Group Options, select the Suppress Subtotal checkbox

Click OK

Now save and run the report.
Here's how the reports look with and without the Totals
With Totals


Without Totals



That's it we have suppressed the Grand/Sub totals in a Cross-tab Crystal report.

Crystal Reports SubReport in Asp.Net


In this post Crystal Reports SubReport report, we shall see on how to create a Subreport report using Crystal Reports, and display the results in an Asp.Net page using the CrystalReportViewer control.

A Crystal Report can hold multiple sub-reports, each of which is an individual report by itself. We can create a main report and add sub-reports to each section of the main report, this will help us in designing complex reports.

Monday, June 11, 2012

Crystal Reports CrossTab Report in Asp.Net


In this post Crystal Reports CrossTab report, we shall see on how to create a Cross Tab report using Crystal Reports, and display the results in an Asp.Net page using the CrystalReportViewer control.

A Crosstab report is a Matrix kind of a report, it shows the relation between 2 parameters, one of the parameter is represented row wise and the other parameter is represented column wise and the matrix cells show the relation between the parameters represented in the rows and columns.