你好,你的报表是参数报表是吧!这是由于你导出的时候没有吧对应的报表数据给在报表展示导致的。
你需要先顶一个 报表的全局变量 Report,然后再导出,具体可以参考下这代码:public GrapeCity.ActiveReports.PageReport Report;
- public GrapeCity.ActiveReports.PageReport Report;
- public Main()
- {
- InitializeComponent();
- Report = new GrapeCity.ActiveReports.PageReport(new FileInfo(@"多条件级联模糊过滤.rdlx"));
- //Report.Report.ReportParameters[0].DefaultValue.Values.Add("15");
- //Report.Document.LocateDataSource += new LocateDataSourceEventHandler(LocateData);
- viewer1.LoadDocument(Report.Document);
- this.viewer1.Sidebar.SelectedIndex = 3;
- this.viewer1.Sidebar.Visible = true;
- }
- public void LocateData(object sender, LocateDataSourceEventArgs args)
- {
- #region
- if (args.DataSet.Query.DataSourceName == "DataSource1")
- {
- if (args.DataSet.Name == "DataSet1")
- {
- var name = args.Parameters[0].Value.ToString();
- List<FormData> data = new List<FormData>();
- for (int i = 1; i <= 3; i++)
- {
- for (int j = 1; j <= 5; j++)
- {
- for (int k = 1; k <= 2; k++)
- {
- data.Add(new FormData()
- {
- Main = i + "CM主控制器",
- Sub = "T-80" + i + j + "子控制器",
- Variable = "T-80" + i + j + k + ".PV",
- Type = "CV投用情况",
- Active = 0 + (i + j + k) % 2,
- Value = (95 - i / 10.0 + j / 10.0 + k / 100.0) / 100.0
- });
- }
- }
- }
- args.Data = data;
- }
- }
- #endregion
- #region
- if (args.DataSet.Query.DataSourceName == "DataSource2")
- {
- if (args.DataSet.Name == "DataSet2")
- {
- List<TimeInfo> info = new List<TimeInfo>();
- info.Add(new TimeInfo() { Type = "开始时间", Value = Convert.ToDateTime("22/08/2017 09:00:00") });
- info.Add(new TimeInfo() { Type = "结束时间", Value = Convert.ToDateTime("22/08/2017 10:00:00") });
- info.Add(new TimeInfo() { Type = "CV投用指标", Value = 0.95 });
- args.Data = info;
- }
- }
- #endregion
- #region
- if (args.DataSet.Query.DataSourceName == "DataSource3")
- {
- if (args.DataSet.Name == "DataSet3")
- {
- List<Operate> operate = new List<Operate>();
- operate.Add(new Operate() { Number = 1, Type = "SVCTL61", Count = 838 });
- operate.Add(new Operate() { Number = 2, Type = "SVCTL64", Count = 226 });
- operate.Add(new Operate() { Number = 3, Type = "SVCTL23", Count = 222 });
- operate.Add(new Operate() { Number = 4, Type = "SVCTL55", Count = 37 });
- operate.Add(new Operate() { Number = 5, Type = "SVCTL63", Count = 35 });
- operate.Add(new Operate() { Number = 6, Type = "SVCTL01", Count = 30 });
- operate.Add(new Operate() { Number = 7, Type = "SVCTL14", Count = 29 });
- operate.Add(new Operate() { Number = 8, Type = "SVCTL25", Count = 27 });
- operate.Add(new Operate() { Number = 9, Type = "SVCTL02", Count = 26 });
- operate.Add(new Operate() { Number = 10, Type = "SVCTL54", Count = 20 });
- operate.Add(new Operate() { Number = 11, Type = "其他", Count = 969 });
- args.Data = operate;
- }
- }
- #endregion
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"D:\MyPDF");
- outputDirectory.Create();
- // Provide settings for your rendering output.
- GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
- // Reduce the report size and report generation time.
- pdfSetting.OptimizeStatic = true;
- // Set the rendering extension and render the report.
- GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
- GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
- // Overwrite output file if it already exists
- outputProvider.OverwriteOutputFile = true;
- Report.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
- }
复制代码
:
|