reportlets导出的表单式请求

楼主
我是社区第55902位番薯,欢迎点我头像关注我哦~
问题来源:不预览直接导出多个模板为多个sheet (表单post提交)  
传送门---》》》http://bbs.fanruan.com/thread-83267-1-1.html
  1. ;
  2. (function($){
  3. //闭包是一个习惯,防止全局变量泛滥成灾
  4. //定义一个数组保存要导出的报表
  5. var reportlets = [];
  6. var $form = null;
  7. var $format = null;
  8. var $filename = null;
  9. var $reportlets = null;

  10. var createFormItem = function(key,value){
  11.         return $('<input>').attr('type','hidden').attr('name',key).attr('value',value).appendTo($form);
  12. };

  13. var initExportForm = function(){
  14.         if(null == $form){
  15.                 $form = $("<form>").attr('style', 'display:none').attr('target', '').attr('method', 'post').attr('action', FR.servletURL).appendTo('body');
  16.                 $format = createFormItem('format', '' );
  17.                 $filename = createFormItem('__filename__', '' );
  18.                 $reportlets = createFormItem('reportlets', '' );
  19.         }
  20. };

  21. FR.CustomExportor = {
  22.         newExport:function(){
  23.                 reportlets = [];
  24.         },
  25.         addReportletByParamArr : function(cpt,params){
  26.                 var reportlet = {reportlet:cpt};
  27.                 $.each(params,function(idx,value){  
  28.                         reportlet[value.key] =  value.value;
  29.                 });
  30.                 reportlets.push(reportlet);
  31.                 return reportlet;
  32.         },
  33.         addReportletByParamMap : function(cpt,params){
  34.                 var reportlet = {reportlet:cpt};
  35.                 $.each(params,function(key,value){  
  36.                         reportlet[key] = value;
  37.                 });
  38.                 reportlets.push(reportlet);
  39.                 return reportlet;
  40.         },
  41.         export:function(format,filename){
  42.                 initExportForm();
  43.                 $format.attr('value',format);
  44.                 $filename.attr('value', encodeURIComponent(filename) );
  45.                 $reportlets.attr('value',encodeURIComponent( FR.jsonEncode( reportlets ) ) );
  46.                 $form.submit();
  47.                 $format.attr('value','');
  48.                 $filename.attr('value', '' );
  49.                 $reportlets.attr('value','' );
  50.         }
  51. };
  52. })(jQuery);

复制代码
调用方法:
//声明一次导出
FR.CustomExportor.newExport();
//依次把报表和参数扔进去
FR.CustomExportor.addReportletByParamMap('WorkBook2.cpt',{p1:1,p2:2});
FR.CustomExportor.addReportletByParamMap('WorkBook2.cpt',{p1:3,p2:4});
//还有另外一种参数方式
//FR.CustomExportor.addReportletByParamArr('WorkBook2.cpt',[{key:'p1',value:1},{key:'p2',value:2}])
//执行导出,带方式和文件名
FR.CustomExportor.export('excel','test');
这个本质就是调用FR自身的reportlets导出








分享扩散:
参与人数 +2 F豆 +667 +10 F币 +10 理由
传说哥 + 666 + 10 + 10 感谢分享
windy_gui + 1 感谢分享

查看全部评分

沙发
发表于 2016-12-6 22:02:16
第一步~把上面这段JS写道一个js文件里面去~然后放到WebReport下面

第二步~随便找个模板弄个自定义按钮写导出代码,看注释就知道啥意思了

第三步~预览导出~完了~

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部 返回列表