KinnSoft 发表于 2015-6-2 17:17:00

区域报表与页面报表转化成Excel

问下区域报表与页面报表转化成Excel时,方法是不是一致的?
       能够公用吗

frank.zhang 发表于 2015-6-2 17:35:00

您好,
excel导出主要使用XlsExport和Rendering两个方法。
XlsExport可以用于导出rpx和rdlx报表
Rendering只能用于导出rdlx报表。

虽然,XlsExport和Rendering都可以导出rdlx的报表,但是Rendering是最新实现的方法,对很多地方进行了增强。

XlsExport导出rpx格式的报表
      protected void Button5_Click(object sender, EventArgs e)
      {
            GrapeCity.ActiveReports.SectionReport sr = new GrapeCity.ActiveReports.SectionReport();
            System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader(Server.MapPath("") + "\\Reports\\RP_YN_YarnSalesSummary.rpx");
            sr.LoadLayout(xtr);
            xtr.Close();

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

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
            XlsExport1.Export(sr.Document, ms);
            ms.Position = 0;

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=MyExport.xlsx"));
            Response.BinaryWrite(ms.ToArray());
            Response.End();
      }

Rendering导出rdlx格式的报表
      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();
      }

希望能帮助到您。

KinnSoft 发表于 2015-6-2 18:02:00

改动这么大,原来封装好的,就不能用了。

frank.zhang 发表于 2015-6-3 09:14:00

您好,
我的建议是保留原有方法,如果是区域报表使用新的导出方法。

另外,在通常的情况下,我们建议使用RDL报表。
RDL报表和区域报表的区别详见:
http://gcdn.gcpowertools.com.cn/showtopic-17065.html
希望能帮助到您。

KinnSoft 发表于 2015-6-3 16:01:00

:An unexpected error occured. Additional information: 'No data has been set. Please specify either a DataSet or a DataView to use'
SourceError:GrapeCity.ActiveReports.v9

    请问      _reportRuntime.Render(excelRenderingExtension, outputProvider, excelSetting.GetSettings());这个函数对_reportRuntime对报表数据源是怎么取得, 因为我的数据源一般是重新加载的,但是这样调用之后,过不了。

KinnSoft 发表于 2015-6-3 16:25:00

回复 5楼KinnSoft的帖子

      我自己解决了, ok。

frank.zhang 发表于 2015-6-3 16:46:00

回复 6楼KinnSoft的帖子

感谢您对我们的反馈

KinnSoft 发表于 2015-6-5 11:53:00

请问转化成Pdf的新方法,有没有
            pdfExport.Security.Encrypt = true;
            pdfExport.Security.Use128Bit = true;

   这些类似属性。旧的方法是有 GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport 有这个属性。

frank.zhang 发表于 2015-6-5 14:00:00

您好,
新的导出方法里面使用到了一个类
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new
            GrapeCity.ActiveReports.Export.Pdf.Page.Settings();

里面有
            pdfSetting.Encrypt = true;
            pdfSetting.Use128Bit = true;

详细的参数可以见,安装包里附带的ActiveReports9.chm文档


KinnSoft 发表于 2015-6-5 15:23:00

ok,不过好像旧的方法,已经挺不错的了,不知道你们改进了什么地方。
页: [1] 2
查看完整版本: 区域报表与页面报表转化成Excel