1. 程式人生 > >水晶報表直接輸出到頁面,不儲存PDF檔案

水晶報表直接輸出到頁面,不儲存PDF檔案

private string ReportFileFolder = HttpContext.Current.Server.MapPath("~/") + @"Reports\";  

public ReportDocument OrderReport()
        {
            ReportDocument report = GetReportDocument();
            report.SetDataSource(new List<T>());
            return report;
        }

private ReportDocument GetReportDocument()

        {
                ReportDocument report = new ReportDocument();
                string path =  "模板路徑"+"模板名" ;

                report.Load(path);

//獲取水晶報表中控制元件並且賦值,不能賦值Null

                ((TextObject)report.ReportDefinition.ReportObjects["txtReportTitle"]).Text = ReportTitle;
                return report;
        }
//輸出到頁面
ReportDocument report = OrderReport();
            ExportOptions exportOpts = new ExportOptions();
            PdfRtfWordFormatOptions pdfOpts = ExportOptions.CreatePdfRtfWordFormatOptions();
            exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
            exportOpts.ExportFormatOptions = pdfOpts;
            report.ExportToHttpResponse(exportOpts, System.Web.HttpContext.Current.Response, false, "");