Appearance

导出为excel

这里我们提供了通用导出为 excel 方法 和从 datagrid 导出为 excel 方法。

参数说明

使用 导出需要 require 'export' 文件

require(["export","pub"],function(exportFn){
  ...
    /*

  * 通用导出excel函数
  *  excel: (
  *   data: Record<string,string|number>[], //导出数据
  *   cols: gridCol[], //导出对应的列 ,有 field,title, hidden?
  *   fileName: string //导出文件名
  *  ) => excel下载文件
  *
  *
  * 根据 grid 导出excel
  * gridToExcel(opt)
  * opt : {
  *     grid: '#gridBox', // grid id,默认为 #gridBox
  *     fileName : '下载文件', //导出文件名,默认为 下载文件
  *     cols : null, // 导出列,同 excel方法 cols
  *     data : null //导出数据 ,同 excel方法 data
  * }
  * */
 // excel 方法
 exportFn.excel(data, col, fileName);

//gridToExcel 方法
 exportFn.gridToExcel({
    grid: '#gridBox', //默认为 gridBox,如果不同,需要填写此字段
    fileName : '下载文件', //导出的文件名称
    cols : null, // 导出列,默认为 grid 的 columns对应列,如果不同,请手动给出
    data : null // 数据,默认为 grid  getRows 获取来的数据,如果不同,请手动给出
 });

});

示例代码

require(["export","pub"],function(exportFn){

        $('.btn-exportExcel').click(function () {
            exportFn.gridToExcel({
                grid:'#gridBox-1'
            });
        });

}