Friday, April 01, 2011

Export Crystal Report To Excel File


 Dim rpt As New ReportDocument
        rpt.Load(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\r12.rpt")
        Dim strSelectionFormula As String = "{Employees.BirthDate} in #" & _
        DateTimePicker1.Value & "# to #" & DateTimePicker2.Value & "#" & _
        " AND {Employees.Title} = '" & ComboBox1.Text & "'"
        rpt.RecordSelectionFormula = strSelectionFormula
        rpt.ExportToDisk(ExportFormatType.Excel, "D:\Report1.xls")

10 comments:

  1. Sir, how to export data directly from datagridview to excel file or pdf file?

    ReplyDelete
  2. @Mit if you don't want any filtration to data (To Display all data) you just have to write :

    Dim rpt As New ReportDocument
    rpt.Load(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\r12.rpt")

    rpt.ExportToDisk(ExportFormatType.Excel, "D:\Report1.xls")

    The work will be done

    ReplyDelete
  3. Sir, above code is not working...
    Error is : load report failed

    ReplyDelete
  4. @Mit just change the path of ur report file
    rpt.Load(Application.StartupPath.Substring(0, Application.StartupPath.Length - 10) + "\r12.rpt")

    I had used my application directory u have to give actual path of your report file

    ReplyDelete

Thanks for showing your interest
I will shortly get back to you