Solved

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

Posted on 2014-01-03
2
618 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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