Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-03
2
Medium Priority
?
646 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

670 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