1,105,402 Community Members

How to export the crystal reports to Excel pdf etc...

Member Avatar
lavanya uppala
Newbie Poster
12 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I am trying to How to export the crystal reports to Excel pdf etc. I am not getting the solution it shows the invalid path but i am giving correct path.pls suggest me,How to solve the problem.
Thanks in Advance.

LastMitch
Deleted Member
 
0
 

@lavanya uppala

I am trying to How to export the crystal reports to Excel pdf etc. I am not getting the solution it shows the invalid path but i am giving correct path.pls suggest me,How to solve the problem.

I think you have to do this manually.

You can try this code:

http://www.codeproject.com/Articles/146377/How-to-Export-Crystal-Reports-Without-Using-the-Re

Member Avatar
arun1123
Newbie Poster
21 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

You can try this link for exporting data to excel in vb.net and procedure will also be application in Asp.net too.

http://www.encodedna.com/2012/12/export-data-to-excel.htm

And to export your crystal report data to PDF try the below function.

Sub printReport()
    ' FIRST ADD REFERENCES.
    ' CrystalDecisions.CrystalReports.Engine
    ' CrystalDecisions.ReportSource

    Dim Report As CrystalDecisions.CrystalReports.Engine.ReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
    Dim CrystalReportViewer As CrystalDecisions.Web.CrystalReportViewer = New CrystalDecisions.Web.CrystalReportViewer

    CrystalReportViewer.BorderStyle = BorderStyle.Solid                 ' OPTIONAL
    CrystalReportViewer.DisplayGroupTree = False                        ' OPTIONAL
    CrystalReportViewer.Zoom(150)                                       ' OPTIONAL
    CrystalReportViewer.HasCrystalLogo = False

    CrystalReportViewer.BestFitPage = False             ' SET THIS FALSE, SO YOU CAN SET THE WIDTH AND HEIGHT.
    CrystalReportViewer.Width = "1200" : CrystalReportViewer.Height = "800"

    ' NOW LOAD THE REPORT.
    Report.Load(System.AppDomain.CurrentDomain.BaseDirectory() & "\reports\" & YourCrystalFileName & "")

    ' NOW EXPORT THE DATA TO A "PDF" FILE.

    Dim sPath_N_File As String = ""
    sPath_N_File = "FOLDER\TESTFILE.pdf"

    Report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
    Report.ExportToDisk(ExportFormatType.PortableDocFormat, Server.MapPath(sPath_N_File))
End Sub
Member Avatar
Ajusha
Newbie Poster
5 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Crystal report itsel can export to pdf and excel, but you have to install Office interop. Here I introduce you a data export component that can export data to PDF, excel, word, html, xml etc without using any third party library. http://www.e-iceblue.com/Introduce/data-export-for-net-intro.html.

you can see below code:

protected void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft)
{
    selectedReport.ExportOptions.ExportFormatType = eft;

    string contentType ="";
    // Make sure asp.net has create and delete permissions in the directory
    string tempDir = System.Configuration.ConfigurationSettings.AppSettings["TempDir"];
    string tempFileName = Session.SessionID.ToString() + ".";
    switch (eft)
    {
    case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat : 
        tempFileName += "pdf";
        contentType = "application/pdf";
        break;
    case CrystalDecisions.Shared.ExportFormatType.WordForWindows : 
        tempFileName+= "doc";
        contentType = "application/msword";
        break;
    case CrystalDecisions.Shared.ExportFormatType.Excel : 
        tempFileName+= "xls";
        contentType = "application/vnd.ms-excel";
        break;
    case CrystalDecisions.Shared.ExportFormatType.HTML32 : 
    case CrystalDecisions.Shared.ExportFormatType.HTML40 : 
        tempFileName+= "htm";
        contentType = "text/html";
        CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions();
        hop.HTMLBaseFolderName = tempDir;
        hop.HTMLFileName = tempFileName;
        selectedReport.ExportOptions.FormatOptions = hop;
        break;
    }

    CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    dfo.DiskFileName = tempDir + tempFileName;
    selectedReport.ExportOptions.DestinationOptions = dfo;
    selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

    selectedReport.Export();
    selectedReport.Close();

    string tempFileNameUsed;
    if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40)
    {
        string[] fp = selectedReport.FilePath.Split("\\".ToCharArray());
        string leafDir = fp[fp.Length-1];
        // strip .rpt extension
        leafDir = leafDir.Substring(0, leafDir.Length – 4);
        tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName);
    }
    else
        tempFileNameUsed = tempDir + tempFileName;

    Response.ClearContent();
    Response.ClearHeaders();
    Response.ContentType = contentType;

    Response.WriteFile(tempFileNameUsed);
    Response.Flush();
    Response.Close();

    System.IO.File.Delete(tempFileNameUsed);
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article