Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I'm using crystal report and in that report I have two buttons. One button is generate another one show to report in excel.
Please solve my problem.
I wrote this code.

C#
private void btnexcel_Click(object sender, EventArgs e)
        {
            try
            {
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = "C:\\Documents and Settings\\Admin\\Desktop\\EmployeeAttendanceEntry.xlsx";
                CrExportOptions = crystalReportViewer1.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                crystalReportViewer1.Export();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
  
        }
Posted
Updated 3-Oct-11 19:22pm
v6
Comments
Dirk C De Winnaar 29-Sep-11 11:15am    
Is it giving you a error?
CodingLover 4-Oct-11 1:23am    
Edit: wrap the code with relevant tags.

Your question is a bit vague on what you want, but if I understand it correctly you wish to show your Crystal report in Excel.

Check these link on how to export a Crystal report to Excel:
In C# how to export from crystal report to excel file[^]
C# Crystal Reports Export to Excel [^]
Exporting from Crystal Reports to PDF, Word, Excel and HTML[^]
 
Share this answer
 
Comments
Espen Harlinn 3-Oct-11 15:17pm    
Nice links :)
André Kraak 3-Oct-11 17:24pm    
Thanks
C#
CrystalReportViwer1.ReportSource = crystalReport;
        if (typ == "Excel")
            crystalReport.ExportToHttpResponse(ExportFormatType.Excel, Response, false, "PackListDetail");



I hope it will help you.
let me know if it get solved using above.

Yogesh.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900