找回密码
 立即注册

QQ登录

只需一步,快速开始

西安风展软件
金牌服务用户   /  发表于:2015-10-26 14:28  /   查看:3227  /  回复:2
.net报表导出word的操作。

2 个回复

倒序浏览
frank.zhang
社区贡献组   /  发表于:2015-10-26 15:15:00
沙发
您好,

导出可以参考以下代码:
  1.         protected void btnWord_Click(object sender, EventArgs e)
  2.         {
  3.             // Provide the page report you want to render.
  4.             string report = "rptInvoice";
  5.             GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("~/Reports/" + report + ".rdlx")));
  6.             _reportDef.Report.DataSources[0].DataSourceReference = "";
  7.             _reportDef.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
  8.             _reportDef.Report.DataSources[0].ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("~/Data/NWind_CHS.mdb"));

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

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


  12.             // Provide settings for your rendering output.
  13.             GrapeCity.ActiveReports.Export.Word.Page.Settings wordSetting = new
  14.             GrapeCity.ActiveReports.Export.Word.Page.Settings();
  15.             wordSetting.UseMhtOutput = true;
  16.             GrapeCity.ActiveReports.Extensibility.Rendering.ISettings setting = wordSetting;

  17.             //Set the rendering extension and render the report.
  18.             GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension wordRenderingExtension =
  19.             new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
  20.             GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
  21.             _reportRuntime.Render(wordRenderingExtension, outputProvider, wordSetting);

  22.             Response.ContentType = "application/msword";
  23.             Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.doc"));
  24.             outputProvider.GetPrimaryStream().OpenStream().CopyTo(ms);
  25.             Response.BinaryWrite(ms.ToArray());
  26.             Response.End();
  27.         }
复制代码
回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-11-9 17:53:00
板凳
为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部