解决fastadmin自带导出excel打开报文件格式和扩展名不匹配的问题

      发布在:前端技术      评论:0 条评论

5dca2ecc-6199-4e09-bd6f-4b3c1a3cb7d6

虽然可以打开看到里面的内容,但是给人的感觉就是很不爽,于是分析下代码找到了解决方法

找到文件public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.js

大概在97行

把代码

require(['tableexport'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: type,
       escape: false
   }));
});

替换成

if(type == 'excel'){
require(['tableexport','/assets/libs/tableExport.jquery.plugin/libs/js-xlsx/xlsx.core.min.js'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type:'excel',
           mso: { fileFormat: 'xlsx' }
}));
   });
}else{
require(['tableexport'], function () {
that.$el.tableExport($.extend({}, that.options.exportOptions, {
type: type,
           escape: false
       }));
   });
}

这里需要引入文件

/assets/libs/tableExport.jquery.plugin/libs/js-xlsx/xlsx.core.min.js

所以可以去https://github.com/hhurz/tableExport.jquery.plugin下载引入

后端引入的是压缩包文件,所以这里需要把文件public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.js压缩成public/assets/libs/bootstrap-table/dist/extensions/export/bootstrap-table-export.min.js文件

热门推荐