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")

Export Crystal Report To PDF 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.PortableDocFormat, "D:\Report1.pdf")

Crystal Report Selection Formula


Dim strSelectionFormula As String = "{Employees.BirthDate} in #" & _
        DateTimePicker1.Value & "# to #" & DateTimePicker2.Value & "#" & _
        " AND {Employees.Title} = '" & ComboBox1.Text & "'"
        CrystalReportViewer1.SelectionFormula = strSelectionFormula
       CrystalReportViewer1.RefreshReport()