找回密码
 立即注册

QQ登录

只需一步,快速开始

frank.zhang
社区贡献组   /  发表于:2015-6-2 17:35:00
沙发
您好,
excel导出主要使用XlsExport和Rendering两个方法。
XlsExport可以用于导出rpx和rdlx报表
Rendering只能用于导出rdlx报表。

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

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

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

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

  12.             Response.ContentType = "application/vnd.ms-excel";
  13.             Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=MyExport.xlsx"));
  14.             Response.BinaryWrite(ms.ToArray());
  15.             Response.End();
  16.         }
复制代码


Rendering导出rdlx格式的报表
  1.         protected void Button3_Click(object sender, EventArgs e)
  2.         {
  3.             // Provide the page report you want to render.
  4.             GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("/Reports/" + report + ".rdlx")));
  5.             _reportDef.Report.DataSources[0].DataSourceReference = "";
  6.             _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
  7.             _reportDef.Report.DataSources[0].ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("/Data/NWind_CHS.mdb"));

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

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

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

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

  23.             Response.ContentType = "application/vnd.ms-excel";
  24.             Response.AddHeader("content-disposition", "inline;filename=MyExport.xls");
  25.             outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
  26.             Response.BinaryWrite(ms.ToArray());
  27.             Response.End();
  28.         }
复制代码


希望能帮助到您。
回复 使用道具 举报
12
您需要登录后才可以回帖 登录 | 立即注册
返回顶部