找回密码
 立即注册

QQ登录

只需一步,快速开始

天狼子e

论坛元老

5

主题

30

帖子

5035

积分

论坛元老

积分
5035

活字格认证

天狼子e
论坛元老   /  发表于:2014-4-23 17:57  /   查看:13990  /  回复:23
有没有mvc3下ar8控件导出pdf,word和excel的示例程序?
能否提供一个简单的sample给我,谢谢

23 个回复

倒序浏览
roger.wang
社区贡献组   /  发表于:2014-4-24 09:35:00
沙发
回复 1楼天狼子e的帖子

请参考 ActiveResports官方资源集合贴,搜索“ActiveReports 中基于Web客户端的报表导出实现方法”,用JavaScript导出试试。
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 10:50:00
板凳
用那个JavaScript不行,不支持PageLoaded方法
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 11:30:00
地板
能否在ar8下载包里面的mvc sample上面给我加个导出示例?谢谢

本帖子中包含更多资源

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

x
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 13:04:00
5#
经过js跟踪,发现ar8控件的id会再前面加一个"1_",比如我的控件名字是WebViewer1,则在页面中viewer控件的clientid属性是"1_WebViewer1",请解释这个原因,另外如下代码根本不会被运行:
  var viewMode;
        $(document).ready(function () {
            $('#WebViewer1').bind('loaded', function () {
                viewMode = GetViewModel('WebViewer1');
            });
        });

本帖子中包含更多资源

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

x
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 13:09:00
6#
修改导出按钮代码如下:

       function Button1_onclick() {
           viewMode = GetViewModel('1_WebViewer1');
           if (viewMode.PageLoaded()) {
               viewMode.Export(ExportType.Pdf, function (uri) {
                   window.location = uri;
               }, true, { FileName: "ActiveReports报表.pdf" });
           }
       }
能导出pdf文件,但是chart被移到了两页数据之间,见附件

本帖子中包含更多资源

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

x
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2014-4-24 14:31:00
7#
天狼子e

在MVC3中还可以使用以下方法导出报表为Excel、PDF等格式文件,在Controller中通过Action导出文件:


  1.     public void Export()
  2.     {
  3.         ReportClass model = new ReportClass();
  4.         Reports.SectionReport1 s_report = new Reports.SectionReport1();
  5.         s_report.Run();

  6.         System.IO.MemoryStream ms = new System.IO.MemoryStream();
  7.         GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport(); xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
  8.         xlsExport1.Export(s_report.Document, ms);

  9.         Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  10.         Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=Test1.xlsx"));
  11.         Response.BinaryWrite(ms.ToArray());            
  12.     }
复制代码

本帖子中包含更多资源

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

x
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 14:36:00
8#
这种情况对于有报表参数的怎么使用?
回复 使用道具 举报
ZenosZeng讲师达人认证 悬赏达人认证
超级版主   /  发表于:2014-4-24 14:46:00
9#
回复 8楼天狼子e的帖子

这样可以传递过滤参数
  1.     public void Export()
  2.     {
  3.         ReportClass model = new ReportClass();
  4.         Reports.SectionReport1 s_report = new Reports.SectionReport1();
  5.         s_report.Parameters[0].Value = "1";
  6.         s_report.Run();

  7.         System.IO.MemoryStream ms = new System.IO.MemoryStream();
  8.         GrapeCity.ActiveReports.Export.Excel.Section.XlsExport xlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport(); xlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
  9.         xlsExport1.Export(s_report.Document, ms);

  10.         Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  11.         Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=Test1.xlsx"));
  12.         Response.BinaryWrite(ms.ToArray());            
  13.     }
复制代码


同时,你提到JS导出之后图表的问题,有可能是纸张高度不够显示图表,所以被显示到下一页。
如果方便你可以将这个报表的模板发送给我测试一下,看正式版本中是否能够显示在同一页中。
回复 使用道具 举报
天狼子e
论坛元老   /  发表于:2014-4-24 16:33:00
10#
  1. <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
  2. <%@ Register Assembly="GrapeCity.ActiveReports.Web.v8" Namespace="GrapeCity.ActiveReports.Web" TagPrefix="ActiveReportsWeb" %>

  3. <head id="Head1" runat="server">
  4.     <title>ReportViewer</title>

  5.     <script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
  6.    <%-- <link rel="stylesheet" type="text/css" href="../../Content/Site.css"/>--%>



  7. <script type="text/javascript">

  8.        var viewMode;
  9.      //  viewMode = GetViewModel('1_WebViewer1');
  10.      //  viewMode.culture = "zh-CN";
  11.        $(document).ready(function () {
  12.            $('#WebViewer1').bind('loaded', function () {
  13.                viewMode = GetViewModel('1_WebViewer1');
  14.            });
  15.        });

  16.        function Button1_onclick() {
  17.            viewMode = GetViewModel('1_WebViewer1');
  18.            if (viewMode.PageLoaded()) {
  19.                viewMode.Export(ExportType.Pdf, function (uri) {
  20.                    window.location = uri;
  21.                }, true, { FileName: "ActiveReports报表.pdf" });
  22.            }
  23.        }

  24.        function Button2_onclick() {
  25.            viewMode = GetViewModel('1_WebViewer1');
  26.            if (viewMode.PageLoaded()) {
  27.                viewMode.Export(ExportType.Xls, function (uri) {
  28.                    window.location = uri;
  29.                }, true, { FileName: "ActiveReports报表.xls" });
  30.            }
  31.        }

  32.        function Button3_onclick() {
  33.            viewMode = GetViewModel('1_WebViewer1');
  34.            if (viewMode.PageLoaded()) {
  35.                viewMode.Export(ExportType.Word, function (uri) {
  36.                    window.location = uri;
  37.                }, true, { FileName: "ActiveReports报表.doc" });
  38.            }
  39.        }
  40.     </script>
  41. </head>
  42. <script runat="server">
  43.     void Page_Load(){
  44.       //  System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
  45.     //    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
  46.         WebViewer1.Report = ViewBag.Report;
  47.         //WebViewer1.
  48.     }
  49.                                       
  50. </script>
  51.   <script Language="javascript" type="text/javascript">
  52.       function viewer_loaded() {
  53.        //   alert("loaaded");s
  54.           var viewModel = GetViewModel('1_WebViewer1');
  55.           //$('#customToolbar').appendTo($('#controlTable');
  56.           $('#customToolbar').appendTo('.arvToolBar');

  57.       };
  58.       function document_onload() {
  59.           $('#1_WebViewer1').bind('loaded', viewer_loaded);

  60.       };
  61.       function exportPDF() {

  62.           var viewModel = GetViewModel('1_WebViewer1');

  63.           if (viewModel.PageLoaded()) {
  64.               viewModel.Export(ExportType.Pdf, function (uri) {
  65.                   window.location = uri;
  66.               }, true, { FileName: "ActiveReports报表.pdf" });
  67.           }
  68.       }


  69.     </script>
  70.      <body onload="return document_onload()">


  71.   <div id="customToolbar" style = "display:inline"><button onclick='exportPDF()'  style=" width: 105px; font-size: medium; height: 22px;">Export</button>
  72. </div>

  73.     <table>
  74.     <tr>
  75.     <td><input id="Button1" type="button" value="Pdf" onclick="return Button1_onclick()" /></td>
  76.     <td><input id="Button2" type="button" value="Exel" onclick="return Button2_onclick()" /></td>
  77.     <td><input id="Button3" type="button" value="Word" onclick="return Button3_onclick()" /></td>   
  78.     </tr>
  79.     </table>
  80. <div>
  81.     <ActiveReportsWeb:WebViewer ID="WebViewer1"  runat="server" >
  82.        </ActiveReportsWeb:WebViewer>
  83. </div>
  84. </body>
复制代码

摸着石头过河,靠分析页面输出,实现了javascript导出pdf,word,excel的功能,请版主速度更新ar8控件在mvc3下的资源文档,以前的文档在mvc 3下基本都会产生令人困惑的错误
回复 使用道具 举报
123下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部