Avatar of Eric Burton
Eric BurtonFlag for United States of America

asked on 

Use VB.NET to export a Crystal Report to Excel with original report formatting.

I want to use VB.NET to export a formatted Crystal Report to a Microsoft Excel worksheet.

The CrystalReportViewer offers 3 options to export to Excel.  I would like to export using the Microsoft Excel (97-2003)(*.xls) format programmatically..  I do not want to do a data only export.  Thanks!

Visual Basic.NETCrystal ReportsMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Ron Malmstead
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Found this code snippet on the webs.
Protected Sub btnExcel_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim Report As ReportDocument = New ReportDocument()
    Report.Load("d:\Test_WebApplication\EmployeeInfo.rpt"))
    Report.SetDatabaseLogon("sa", "password", "Rakesh-PC", "SqlServerTech")
    Response.Buffer = False
    Response.ClearContent()
    Response.ClearHeaders()
    Report.ExportToHttpResponse(ExportFormatType.Excel, Response, True, "EmployeeInformation")
    Response.[End]()
End Sub

Open in new window


As far as what I've read, it will preserve formatting, except it will omit lines and boxes.
Avatar of Eric Burton
Eric Burton
Flag of United States of America image

ASKER

Thanks Ron!  It looks like the code is from an ASP.NET app - will it work for the desktop also?  
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Eric Burton
Eric Burton
Flag of United States of America image

ASKER

Thanks Eric!  Are you suggesting from the article that the following would work:
ExportToDisk(CrystalDecisions.Shared.ExportFormatType.Excel, strOutputPath)

Open in new window


SOLUTION
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo