sunshiqi 发表于 2015-8-6 16:44:00

AR9支持导出一个数据源是一个DataSet的Excel或者Pdf

AR9支持导出一个数据源是一个DataSet的Excel或者Pdf吗
我的这个DataSet是个从数据库中查出来的








我想导出时候将这个dataset导出来,大神能实现吗?

frank.zhang 发表于 2015-8-6 17:55:00

您好,
我对您的问题理解为,将一个数据源例如DataSet,不经过展示,直接导出为excel或者pdf吗?
如果理解的不正确,希望补充。

sunshiqi 发表于 2015-8-7 08:35:00

对!!按导出按钮不展示直接提示下载

frank.zhang 发表于 2015-8-7 11:01:00

您好,
在AR中,导出是通过PageReport执行的。
可以在按钮中,直接创建一个PageReport,然后导出。不进行显示。
      protected void Button3_Click(object sender, EventArgs e)
      {
            // Provide the page report you want to render.
            GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("/Reports/" + report + ".rdlx")));
            _reportDef.Report.DataSources.DataSourceReference = "";
            _reportDef.Report.DataSources.ConnectionProperties.DataProvider = "OLEDB";
            _reportDef.Report.DataSources.ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("/Data/NWind_CHS.mdb"));

            GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);

            // Create an output directory
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            // Provide settings for your rendering output.
            GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings
            excelSetting = new GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtensionSettings();
            excelSetting.FileFormat = GrapeCity.ActiveReports.Export.Excel.Page.FileFormat.Xls;
            //excelSetting.MultiSheet = false;
            GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = excelSetting;

            //Set the rendering extension and render the report.
            GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension
            excelRenderingExtension = new
            GrapeCity.ActiveReports.Export.Excel.Page.ExcelRenderingExtension();
            GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
            _reportRuntime.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
            outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
            Response.BinaryWrite(ms.ToArray());
            Response.End();
      }


Exep 发表于 2015-8-7 11:21:00

大神把pdf的demo也发一下呗谢谢大神

sunshiqi 发表于 2015-8-7 11:24:00

感谢大神

frank.zhang 发表于 2015-8-7 11:26:00

回复 5楼Exep的帖子

好的,
多问一句,你和楼主是一家公司的吗?

Exep 发表于 2015-8-7 11:29:00

大神其实你猜对了我们都在研究这东西 we are team

frank.zhang 发表于 2015-8-7 13:55:00

您好,
这个问题重复帖,我们在
http://gcdn.gcpowertools.com.cn/showtopic-18107.html继续讨论。

jishaojia 发表于 2015-12-6 00:14:00

回复 4楼frank.zhang的帖子

大神啊。贴主应该是想表达说不要类似
   _reportDef.Report.DataSources.DataSourceReference = "";
            _reportDef.Report.DataSources.ConnectionProperties.DataProvider = "OLEDB";
            _reportDef.Report.DataSources.ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("/Data/NWind_CHS.mdb"));
这样赋值,我们想的是dataset的方法来赋值到里面去导出也和画的报表风格一致。
页: [1] 2
查看完整版本: AR9支持导出一个数据源是一个DataSet的Excel或者Pdf