private string ExportReport(string reportName, List <UserParamValues> paramList, string reportformat = "pdf")
        {
            string repName  = reportName + ".rpt";
            string fileName = reportName + DateTime.UtcNow.ToString("_yyyymmdd_HHmmssfff");

            ReportDocument cryRpt = LoadCrReport(repName);

            SetParameters(paramList, cryRpt);

            ExcelDataOnlyFormatOptions            excelFormatOpts = ExportOptions.CreateDataOnlyExcelFormatOptions(); //new ExcelFormatOptions();
            CharacterSeparatedValuesFormatOptions csvOptions      = new CharacterSeparatedValuesFormatOptions();

            ExportFormatType exportFormat = ExportFormatType.PortableDocFormat;

            switch (reportformat.ToLower())
            {
            case "pdf":
                exportFormat = ExportFormatType.PortableDocFormat;
                fileName     = fileName + ".pdf";
                break;

            case "excel":
                exportFormat = ExportFormatType.ExcelRecord;
                excelFormatOpts.ExcelUseConstantColumnWidth   = true;
                excelFormatOpts.SimplifyPageHeaders           = false;
                excelFormatOpts.ExportPageHeaderAndPageFooter = true;
                excelFormatOpts.ShowGroupOutlines             = false;
                fileName = fileName + ".xls";
                cryRpt.ExportOptions.FormatOptions = excelFormatOpts;

                break;

            case "csv":
                exportFormat                    = ExportFormatType.CharacterSeparatedValues;
                csvOptions.SeparatorText        = ",";
                csvOptions.Delimiter            = "\n";
                csvOptions.ReportSectionsOption = CsvExportSectionsOption.ExportIsolated;
                csvOptions.GroupSectionsOption  = CsvExportSectionsOption.DoNotExport;
                csvOptions.ExportMode           = CsvExportMode.Standard;

                fileName = fileName + ".csv";
                cryRpt.ExportOptions.FormatOptions = csvOptions;

                break;

            default:
                exportFormat = ExportFormatType.PortableDocFormat;
                fileName     = fileName + ".pdf";
                break;
            }
            string filePath = HttpContext.Current.Server.MapPath(outputDir + fileName);

            cryRpt.ExportToDisk(exportFormat, filePath);
            return(filePath);
        }
Exemple #2
0
        private string ExportReport(string reportName, List <UserParamValues> paramList, string reportHeader, string reportformat = "pdf")
        {
            string repName  = reportName + ".rpt";
            string fileName = "L" + LocalSettingsConfig.LocalSettings.LocalNumber + "_" + reportHeader + DateTime.UtcNow.ToString("_yyyymmdd_HHmmssfff");

            ReportDocument cryRpt = LoadCrReport(repName);

            SetParameters(paramList, cryRpt);

            ExcelDataOnlyFormatOptions            excelFormatOpts = ExportOptions.CreateDataOnlyExcelFormatOptions(); //new ExcelFormatOptions();
            CharacterSeparatedValuesFormatOptions csvOptions      = new CharacterSeparatedValuesFormatOptions();

            ExportFormatType exportFormat = ExportFormatType.PortableDocFormat;

            switch (reportformat.ToLower())
            {
            case "pdf":
                exportFormat = ExportFormatType.PortableDocFormat;
                fileName     = fileName + ".pdf";
                break;

            case "excel":
                cryRpt.ReportDefinition.Sections[0].SectionFormat.EnableSuppress = true;
                exportFormat = ExportFormatType.ExcelRecord;
                excelFormatOpts.ExcelUseConstantColumnWidth   = false;
                excelFormatOpts.SimplifyPageHeaders           = true;
                excelFormatOpts.ExportPageHeaderAndPageFooter = false;
                excelFormatOpts.ShowGroupOutlines             = false;
                fileName = fileName + ".xls";
                cryRpt.ExportOptions.FormatOptions = excelFormatOpts;

                break;

            case "csv":
                exportFormat                    = ExportFormatType.CharacterSeparatedValues;
                csvOptions.SeparatorText        = ",";
                csvOptions.Delimiter            = "\n";
                csvOptions.ReportSectionsOption = CsvExportSectionsOption.ExportIsolated;
                csvOptions.GroupSectionsOption  = CsvExportSectionsOption.DoNotExport;
                csvOptions.ExportMode           = CsvExportMode.Standard;

                fileName = fileName + ".csv";
                cryRpt.ExportOptions.FormatOptions = csvOptions;

                break;

            default:
                exportFormat = ExportFormatType.PortableDocFormat;
                fileName     = fileName + ".pdf";
                break;
            }

            //Check if OutputDir exists
            var physicalPath = Server.MapPath(outputDir);

            if (!Directory.Exists(physicalPath))
            {
                Directory.CreateDirectory(physicalPath);
            }
            string filePath = Server.MapPath(outputDir + fileName);

            cryRpt.ExportToDisk(exportFormat, filePath);
            return(filePath);
        }