找回密码
 立即注册

QQ登录

只需一步,快速开始

893559686

初级会员

13

主题

40

帖子

345

积分

初级会员

积分
345

微信认证勋章

893559686
初级会员   /  发表于:2016-8-19 13:09  /   查看:2990  /  回复:3
本帖最后由 Lenka.Guo 于 2016-8-19 14:10 编辑

求助问题:
报表:RDL报表
报表数据源类型为:Object Provider
在导出的时候,如何直接将数据源赋给导出的报表?


示例:
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Microsoft.SqlServer.Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Microsoft.SqlServer.Server.MapPath("../Data/NWind_CHS_Access.rdsx");

示例代码是直接指向数据源文件的,我的数据源是自定义的类,该如何赋给这个报表?




3 个回复

倒序浏览
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-8-19 14:10:25
沙发
您指的是报表数据源类型为Object Provider ,

可以参考博客:[url=http://blog.gcpowertools.com.cn/ ... ListDataSource.aspx]集合对象数据源[/url]

评分

参与人数 1满意度 +5 收起 理由
893559686 + 5 赞一个!

查看全部评分

回复 使用道具 举报
893559686
初级会员   /  发表于:2016-8-19 15:45:16
板凳
Lenka.Guo 发表于 2016-8-19 14:10
您指的是报表数据源类型为Object Provider ,

可以参考博客:http://blog.gcpowertools.com.cn/post/2013/ ...

谢谢,搞定了。

public class EngineeringReportType
    {
        public string ID { get; set; }
        public string Name { get; set; }
        public string Path { get; set; }
        public string FileName { get; set; }

        public Dictionary<string, object> ReportDataSourceDic { get; set; }


    }

  EngineeringReportType aTreeSelectItem =null;

if (aTreeSelectItem != null)
            {
                string aExportPath = string.Empty;//导出路径
                string aNewFileName = aTreeSelectItem.Name+".xlsx";//新文件名

                System.Windows.Forms.FolderBrowserDialog aFolder = new FolderBrowserDialog();
                aFolder.ShowDialog();
                if(!string.IsNullOrWhiteSpace(aFolder.SelectedPath))
                {
                    aExportPath = aFolder.SelectedPath;
                }
                else
                {
                    MessageBox.Show("请选择导出位置"); return;
                }

                string aPath = Utils.SystemSetting.RegSettings.ReportPath + aTreeSelectItem.Path + aTreeSelectItem.FileName;
                GrapeCity.ActiveReports.PageReport _repPage = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(aPath));

                GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_repPage);
                _reportRuntime.LocateDataSource += (send, args) =>
                {
                    object reportData = null;
                    if (aTreeSelectItem.ReportDataSourceDic != null)
                        reportData = aTreeSelectItem.ReportDataSourceDic.Where(i => i.Key.Equals(args.DataSetName)).FirstOrDefault().Value;
                    args.Data = reportData;
                };

                GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();

                xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
                xlsExport1.Export(_reportRuntime, aExportPath + "\\" + aNewFileName);

                MessageBox.Show("导出完成");

            }
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-8-19 16:00:13
地板
893559686 发表于 2016-8-19 15:45
谢谢,搞定了。

public class EngineeringReportType

好快~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部