找回密码
 立即注册

QQ登录

只需一步,快速开始

KinnSoft

高级会员

108

主题

494

帖子

1999

积分

高级会员

积分
1999

活字格认证微信认证勋章元老葡萄

KinnSoft
高级会员   /  发表于:2015-6-2 17:27  /   查看:7074  /  回复:10
问下区域报表与页面报表转化成Excel时,方法是不是一致的?
       能够公用吗

10 个回复

倒序浏览
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.         }
复制代码


希望能帮助到您。
回复 使用道具 举报
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
5#
: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
6#
回复 5楼KinnSoft的帖子

      我自己解决了, ok。

评分

参与人数 1金币 +100 收起 理由
frank.zhang + 100 感谢您对我们的反馈

查看全部评分

回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-6-3 16:46:00
7#
回复 6楼KinnSoft的帖子

感谢您对我们的反馈
回复 使用道具 举报
KinnSoft
高级会员   /  发表于:2015-6-5 11:53:00
8#
请问转化成Pdf的新方法,有没有  
            pdfExport.Security.Encrypt = true;
            pdfExport.Security.Use128Bit = true;

     这些类似属性。  旧的方法是有 GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport 有这个属性。
回复 使用道具 举报
frank.zhang
社区贡献组   /  发表于:2015-6-5 14:00:00
9#
您好,
新的导出方法里面使用到了一个类
  1.             GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new
  2.             GrapeCity.ActiveReports.Export.Pdf.Page.Settings();
复制代码


里面有
  1.             pdfSetting.Encrypt = true;
  2.             pdfSetting.Use128Bit = true;
复制代码


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


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
KinnSoft
高级会员   /  发表于:2015-6-5 15:23:00
10#
ok,  不过好像旧的方法,已经挺不错的了,不知道你们改进了什么地方。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部