- This article discusses how to export Crystal Report on button click into PDF, Excel, Word, HTML, RTF in ASP.NET C#.
- Te dejara el link de la app pero vos sabes que no se puede divulgar te la dejo inbox.
- VB.NET Crystal Reports Load Dynamically All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb). Please take a look at the database structure before you start this tutorial.
Export Crystal Report on Button Click to Word Excel PDF and CSV in ASP. Net. In this article I will explain how to export Crystal Report and download Word, Excel, PDF and CSV file formats in ASP.
Net using C# and VB. Net. HTML Markup. The HTML Markup contains a Crystal. Report. Viewer control, a Radio. Button. List with the export file formats and a Button to Export Crystal Reports to Word, Excel, PDF and CSV file formats.< %@Register.
VB.NET Crystal Reports Export to PDF Exporting from Crystal Reports to PDF format, we are using Crystal Reportss CrExportOptions. Also we have to set PdfRtfWordFormatOptions and ExportFormatType.PortableDocFormat. In the.
I'm having problems with crystal report, if anyone can help.. the problem arises from tables that have a one to many relation ships. in my project i have used three tables, which are EMPLOYEE, LANGUAGE AND ALLOWANCES.In.
Assembly="Crystal. Decisions. Web, Version=1.
Culture=neutral, Public. Key. Token=6. 92fbea.
Namespace="Crystal. Decisions. Web"Tag. Prefix="CR"%> < ! DOCTYPEhtml. PUBLIC"- //W3. C//DTD XHTML 1. 0 Transitional//EN""http: //www. TR/xhtml. 1/DTD/xhtml.
CR: Crystal. Report. Viewer. ID="Crystal.
Report. Viewer. 1"runat="server"Auto. Data. Bind="true" Height="4. Width="6. 00"Best. Fit. Page="False"Tool.
Panel. View="None"/> < br/> Format: < asp: Radio. Button. List. ID="rb.
Format"runat="server"Repeat. Direction="Horizontal"> < asp: List. Item. Text="Word"Value="Word"Selected="True"/> < asp: List. Item. Text="Excel"Value="Excel"/> < asp: List.
Item. Text="PDF"Value="PDF"/> < asp: List. Item. Text="CSV"Value="CSV"/> < /asp: Radio. Button. List> < br/> < asp: Button. ID="btn. Export"Text="Export PDF"runat="server"On.
Click="Export. PDF"/> < /form> < /body> < /html> Namespaces. You will need to import the following namespaces. C#using System. Data; using System. Configuration; using System. Data. Sql. Client; using Crystal.
Decisions. Crystal. Reports. Engine; using Crystal.
Decisions. Shared; VB. Net. Imports System. Data. Imports System. Configuration. Imports System. Data. Sql. Client.
Imports Crystal. Decisions. Crystal. Reports. Engine. Imports Crystal. Decisions. Shared. Designing and populating the Crystal Report from Database.
I will not cover the part of creating, designing and populating the Crystal Reports as that has been done extensively in the following article and this article is an extended feature of the same. Thus please refer the following article for details. In the below code I have done some modifications to the code from the original article.
Instead of binding the Crystal Report directly in Page Load, I have created a method so that it can be used for binding report when page loads as well as when the export button is clicked. C#protectedvoid Page_Load(object sender, Event. Args e){ if (! Is. Post. Back) { Report. Document crystal. Report = new. Report. Document(); Bind.
Report(crystal. Report); }}privatevoid Bind. Report(Report. Document crystal. Report){ crystal. Report. Load(Server.
Map. Path("~/Customer. Report. rpt")); Customers ds. Customers = Get. Data("select top 5 * from customers"); crystal. Report. Set. Data.
Source(ds. Customers); Crystal. Report. Viewer. 1. Report. Source = crystal. Report; }private. Customers Get. Data(string query){ string con. String = Configuration. Manager. Connection.
Strings["constr"]. Connection. String; Sql.
Command cmd = new. Sql. Command(query); using (Sql.
Connection con = new. Sql. Connection(con. String)) { using (Sql. Data. Adapter sda = new. Sql. Data. Adapter()) { cmd. Connection = con; sda.
Select. Command = cmd; using (Customers ds. Customers = new. Customers()) { sda. Fill(ds. Customers, "Data. Table. 1"); return ds. Customers; } } }}VB. Net. Protected. Sub Page_Load(sender As. Object, e As. Event.
Args) Handles. Me. Load If. Not Is. Post. Back Then Dim crystal. Report As. New. Report.
Document() Bind. Report(crystal. Report) End.
If. End. Sub. Private. Sub Bind. Report(crystal. Report As. Report. Document) crystal. Report. Load(Server.
Map. Path("~/Customer. Report. rpt")) Dim ds. Customers As. Customers = Get. Data("select top 5 * from customers") crystal. Report. Set. Data. Source(ds. Customers) Crystal.
Report. Viewer. 1. Report. Source = crystal. Report. End. Sub. Private. Function Get. Data(query As. String) As. Customers Dim con. String As. String = Configuration.
Manager. Connection. Strings("constr"). Connection. String Dim cmd As.
New. Sql. Command(query) Using con As. New. Sql. Connection(con. String) Using sda As. New. Sql. Data. Adapter() cmd. Connection = con sda. Select. Command = cmd Using ds.
Customers As. New. Customers() sda. Fill(ds. Customers, "Data. Table. 1") Return ds. Customers End. Using End.
Using End. Using. End. Function. Exporting Crystal Report and download Word, Excel, PDF and CSV file formats in ASP. Net. The following code is executed on the click of the export button. First I have populated the Crystal Report using the Bind. Report method and then based on the selection from the Radio. Button. List I have set the Export. Format. Type for the Crystal Report.
Finally using the set Export. Format. Type the Crystal Report is exported to the selected format as and downloaded as an attachment in browser.
C#protectedvoid Export. PDF(object sender, Event. Args e){ Report. Document crystal. Report = new. Report.
Document(); Bind. Report(crystal. Report); Export. Format. Type format.
Type = Export. Format. Type. No. Format; switch (rb. Format. Selected. Item. Value) { case"Word": format.
Type = Export. Format. Type. Word. For. Windows; break; case"PDF": format. Type = Export. Format. Type. Portable. Doc. Format; break; case"Excel": format. Type = Export. Format. Type. Excel; break; case"CSV": format.
Type = Export. Format. Type. Character. Separated.
Values; break; } crystal. Report. Export. To. Http. Response(format. Type, Response, true, "Crystal"); Response.
End(); }VB. Net. Protected. Sub Export. PDF(sender As. Object, e As. Event. Args) Dim crystal. Report As. New. Report. Document() Bind. Report(crystal. Report) Dim format.
Type As. Export. Format. Type = Export. Format. Type. No. Format Select.
Case rb. Format. Selected. Item. Value Case"Word" format. Type = Export. Format. Type. Word. For. Windows Exit Select Case"PDF" format.
Type = Export. Format. Type. Portable. Doc. Format Exit Select Case"Excel" format. Type = Export. Format. Type. Excel Exit Select Case"CSV" format.
Type = Export. Format. Type. Character. Separated. Values Exit Select End. Select crystal. Report. Export. To. Http. Response(format.
Type, Response, True, "Crystal") Response.[End]()End. Sub. Screenshots. Crystal Report exported to Word Document. Crystal Report exported to Excel Spreadsheet. Crystal Report exported to PDF file. Crystal Report exported to CSV file.