VB.NET Crystal Reports Export to Excel
To export data from Crystal Reports to the Excel format, we employ the Crystal Reports CrExportOptions. Furthermore, it is essential to configure the ExcelFormatOptions and set the ExportFormatType to Excel. In the subsequent example, you will find a demonstration of how to export a Crystal Reports document as an Excel file.
It is important to note that all the programming samples presented in these tutorials for Crystal Reports are built upon the crystaldb database. Prior to commencing this tutorial, I highly recommend acquainting yourself with the Database Structure. To access the database structure, kindly click on the following link: Click here to view the Database Structure.
In this tutorial, we will be utilizing our previous program, which thoroughly explains the step by step Crystal Report process of pulling data from a database into Crystal Reports. To ensure a comprehensive understanding, I suggest reviewing the step-by-step guide titled "Crystal Report in VB.NET" before proceeding with this section.
In the aforementioned step-by-step Crystal Report guide, we extract all the data from the Product table. However, in the current scenario, our objective is to export this retrieved data to an Excel file format.
Select the default form (Form1.vb) you created in VB.NET and drag two buttons (Button1, Button2 ) and CrystalReportViewer control to your form.
Select Form's source code view and import the following :
Put the following source code in the button click eventsFull Source VB.NET
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")
The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here.
When you run this program you will get the Excel file (crystalExport.xls) in your computer's C: