Solved

ASP.net vb Crystal Report to Excel without using CR to export

Posted on 2014-01-03
2
615 Views
Last Modified: 2014-01-03
I am trying to send a crystal report (Rpt) to excel in asp.net without doing the conversion in the CR or displaying the CR. I get format error. What would be the correct code I need to modify the below?
Thanks

Private Sub ReportToPDF(ByVal Rpt As ReportDocument)
        Dim s As System.IO.MemoryStream = Rpt.ExportToStream(ExportFormatType.PortableDocFormat)
        ' the code below will create pdfs in memory and stream them to the browser
        ' instead of creating files on disk.
        With HttpContext.Current.Response
            .ClearContent()
            .ClearHeaders()
            .ContentType = "application/vnd.ms-excel"
            .AddHeader("Content-Disposition", "attachment; filename=LaborReport.xlsx")
            .BinaryWrite(s.ToArray)
            HttpContext.Current.ApplicationInstance.CompleteRequest()
        End With
    End Sub
0
Comment
Question by:BKennedy2008
  • 2
2 Comments
 

Author Comment

by:BKennedy2008
ID: 39754486
I also changed to :
.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Same Format error
0
 

Accepted Solution

by:
BKennedy2008 earned 0 total points
ID: 39754565
I got this to work
 CrystalReportViewer1.ReportSource = rpt

        Dim strExportFile As String = Server.MapPath(".") & "/WebReport.xls"

        rpt.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
        rpt.ExportOptions.ExportFormatType = ExportFormatType.Excel
        Dim objOptions As DiskFileDestinationOptions = New DiskFileDestinationOptions
        objOptions.DiskFileName = strExportFile
        rpt.ExportOptions.DestinationOptions = objOptions
        rpt.Export()
        objOptions = Nothing
        rpt = Nothing
        Response.Redirect("WebReport.xls")
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now