Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS On fail action 5 38
abstract class C# 1 31
asp.net mvc , views, hidden values ? 2 17
Running powershell scripts from ASP.NET 6 31
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:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…

821 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