Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to export a report created from a database in MySql with a dataset to Word without have to open the crystal report viewer and click it on the export button on it,

is it possible, i searched and below is the code but is not working any help?? tks

C#
ReportDocument report = new ReportDocument();
            report.Load("DiffFileFormatRpt.rpt");
            report.SetDatabaseLogon("user","passwdor","route","database");
            string filetype = cmbFileFomats.Text;
            CrystalDecisions.Shared.ExportFormatType efileType = (CrystalDecisions.Shared.ExportFormatType)Enum.Parse(typeof(CrystalDecisions.Shared.ExportFormatType), filetype);
            switch (efileType)
            {               
                case CrystalDecisions.Shared.ExportFormatType.Excel:
                    report.ExportToDisk(efileType, "reportExcel.xls");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.ExcelRecord:
                    report.ExportToDisk(efileType, "reportExcel.xls");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.HTML32:
                    report.ExportToDisk(efileType, "reporthtml.html");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.HTML40:
                    report.ExportToDisk(efileType, "reporthtml.html");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.NoFormat:
                    report.ExportToDisk(efileType, "reportExcel.xls");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat:
                    report.ExportToDisk(efileType, "reportpdf.pdf");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.RichText:
                    report.ExportToDisk(efileType, "reportrtf.rtf");
                    break;
                case CrystalDecisions.Shared.ExportFormatType.WordForWindows:
                    report.ExportToDisk(efileType, "reportdoc.doc");
                    break;
                default:
                    break;
            }
Posted
Updated 26-Jan-20 17:37pm

Give full path of document
C#
report.ExportToDisk(efileType, "reportExcel.xls"); //instead of this give full path
report.ExportToDisk(efileType, "D:\reportExcel.xls");

then check at location
Happy Coding!
:)
 
Share this answer
 
CrystalReport1 cr = new CrystalReport1();
            cr.SetDataSource(ds.Tables[0]);
            cr.ExportToDisk(ExportFormatType.PortableDocFormat, @"E:\Bills\OK.pdf");
            cr.SetDataSource(ds);
            crystalReportViewer1.ReportSource = cr;
 
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