码迷,mamicode.com
首页 > Web开发 > 详细

将Jquery EasyUI中DataGird的数据导入Excel中

时间:2015-03-13 15:51:59      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

1.第一步获取前台DataGrid中的数据

var rows = $(‘#tb).datagrid("getRows");
            if (rows.length == 0) {
                $("#ShowMsg").html("没有数据可供导出!");
                return;
            }
            var columns = new Array();
            var fields = $(‘#tb).datagrid(‘getColumnFields‘);
            for (var i = 0; i < fields.length; i++) {
                var opts = $(‘#tb).datagrid(‘getColumnOption‘, fields[i]);
                var column = new Object();
                column.field = opts.field;
                column.title = opts.title;
                columns.push(column);
            }
            var excelWorkSheet = new Object();
            excelWorkSheet.rows = rows;
            excelWorkSheet.columns = columns;
            excelWorkSheet.sheetName = "名字";
          

2.发布Post请求到后台

   $.post("XXXX.aspx", { IsAction: ‘Method‘, ActType: ‘exportXls‘,
                ExcelWorkSheet: JSON.stringify(excelWorkSheet) //将数据转化为Json字符串
            },
                function (data) {
                    成功后操作
                  }
            );

3.在后台将Json串转化为Datatable后写入到Excel模版中;

将Jquery EasyUI中DataGird的数据导入Excel中

标签:

原文地址:http://www.cnblogs.com/bluestream/p/4335106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!