layui table 重写导出Excel 复杂表头

layui table 重写导出Excel 复杂表头_第1张图片

 效果如上,代码如下

layui.extend({
        excel:basePath+'/js/layui_exts/excel'
    });

layui.use(['excel'],function(){
    var excel = layui.excel;
});

var data = [

                    {id: 'ID', username: 'wang0', age: '', sex: '', score: '100', classify: ''},
                    {id: 'id', username: 'wang1', age: '1', sex: '2', score: '绉垎', classify: '一年级'},
                    {id: 1, username: 'wang2', age: 10, sex: '2', score: 100, classify: '二年级'},
                    {id: 1, username: 'wang3', age: 10, sex: '3', score: 100, classify: '三年级'},
                    {id: 1, username: 'wang4', age: 10, sex: '4', score: 100, classify: '四年级'},
                    {id: 1, username: 'wang5', age: 10, sex: '5', score: 100, classify: '五年级'},
                    {id: 1, username: 'wang6', age: 10, sex: '6', score: 100, classify: '六年级'},
                    {id: 1, username: 'wang7', age: 10, sex: '7', score: 100, classify: '七年级'},
                    {id: 1, username: 'wang8', age: 10, sex: '8', score: 100, classify: '八年级'},
                ]
                // 1. 合并 列
                var mergeConf = excel.makeMergeConfig([
                    ['B1', 'F1'],['A1','A2'],
                    ['B2', 'D2'],
                    ['E2', 'F2'],
                ])
                // 2. 列宽
                var colConf = excel.makeColConfig({
                    'B': 150,
                    'F': 200
                }, 80)
                // 3.
                var rowConf = excel.makeRowConfig({
                    1: 40,
                    3: 30
                }, 20)
                excel.exportExcel({
                    sheet1: data,
                    sheet2: data
                }, '测试.xlsx', 'xlsx', {
                    extend: {
                        sheet1: {
                            '!merges': mergeConf
                            , '!cols': colConf
                            , '!rows': rowConf
                        }
                    }
                })

你可能感兴趣的:(layui,layui,前端,javascript)