Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-03
2
Medium Priority
?
651 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

879 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