Exports generated crystal report into Excel Format & download.

1.First Create crystal report.
2.Create Interface to display report (i.e aspx Form) in that add Crystal Viewer (CrystalReportViewer1) & Command Button (btnExToExcel).
3.Change report name into CallReport().
4.CrystalReportViewer1 is an ID of Crystal Report Viewer. AND btnExToExcel is an ID of command button.

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Web
Imports CrystalDecisions.Shared
Imports CrystalDecisions.ReportSource

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
End If
End Sub

Private Sub CallReport()
Dim objDS As New DataSet

Dim EmpReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim rptFile As String = Server.MapPath("rptEmployee.rpt")

Session("Emprpt") = EmpReportDoc

''Create Dataset as per requirement


Me.CrystalReportViewer1.ReportSource = EmpReportDoc
End Sub

#Region " Export To Excel "

Protected Sub btnExToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExToExcel.Click

Dim objEmpDoc As New ReportDocument
objEmpDoc = Session("Emprpt")

Dim oStream As MemoryStream = objEmpDoc.ExportToStream(ExportFormatType.Excel)

With HttpContext.Current.Response



.ContentType = "application/xls"

.AddHeader("Content-Disposition", "attachment; filename=Employee Details.xls")




End With

End Sub

#End Region

-Thanks & Regards,


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: