Remove some parts in FastReport using C#

1.8k views Asked by At

I am using FastReport in ASP.net MVC. I wrote some code for removing the report title when exporting to Excel. It works properly. But sometimes the report is shown and after that export method is called; in this case when I push the Next Page button in FastReport's toolbar, I see that the report title was removed. I wrote this:

FastReport.Utils.Config.WebMode = true;
ExportBase export = null;
var webReportExport = new WebReport();
//keep werreport object in tempdata in first loading of report for using it to export later
webReportExport.Report = TempData["WebReport"] as FastReport.Report;

webReportExport.Report.FindObject("PageHeader1").Delete();
webReportExport.Report.FindObject("PageFooter1").Delete();

TempData.Keep("WebReport");

ViewBag.WebReport = TempData["WebReport"] as FastReport.Report;
if (webReportExport.Report.Prepare())
{      
    switch (exportType)
    {
         case "pdf": export = new FastReport.Export.Pdf.PDFExport();  break;
         case "excel": export = new FastReport.Export.OoXML.Excel2007Export() ; break;
         case "word": export = new FastReport.Export.OoXML.Word2007Export(); break;
         case "rtf": export = new FastReport.Export.RichText.RTFExport(); break;
         default:
             break;
    }

    export.ShowProgress = false;
    MemoryStream strm = new MemoryStream();
    webReportExport.Report.Export(export, strm);
    webReportExport.Dispose();
    export.Dispose();
    strm.Position = 0;


    var currentDate = PersianDate.Parse(PersianDateConverter.ToPersianDate(DateTime.Now).ToString()).ToString("swt");
    var reportName = TempData["reportName"] + currentDate;
    switch (exportType)
    {
        case "pdf": return File(strm, "application/pdf", reportName+".pdf"); break;
        case "excel": return File(strm, "application/ms-excel", reportName+".xlsx"); break;
        case "word": return File(strm, "application/vnd.openxmlformats-officedocument.wordprocessingml.document",reportName+ ".docx"); break;
        case "rtf": return File(strm, "application/rtf", reportName+".rtf"); break;
        default:
            break;
    }
}
return null;
0

There are 0 answers