fastadmin默认导出图片全部都再一块,而且不在单元格里
话不多说,上代码
修改文件的路径:
/public/assets/js/require-table.js
exportOptions: {fileName: 'export_' + Moment().format("YYYY-MM-DD"),preventInjection: false,mso: {onMsoNumberFormat: function (cell, row, col) {var h = 80 //这块是修改行高,可根据需要自行调整return !isNaN($(cell).text()) ? '\\@\';height:\''+h+'px' : '';},},ignoreColumn: [0, 'operate'], //默认不导出第一列(checkbox)与操作(operate)列//----------修改图片样式--start---------------这部分就是新增加的代码htmlContent: true,// 处理导出图片onCellHtmlData: function ($cell, row, col, htmlData) {var html = $.parseHTML(htmlData);var inputidx = 0;var selectidx = 0;var result = '';$.each(html, function () {if ($(this).is("input")) {result += $cell.find('input').eq(inputidx++).val();} else if ($(this).is("select")) {result += $cell.find('select option:selected').eq(selectidx++).text();} else if ($(this).is("a")) {// 安全处理 <a> 标签内的 <img>var $a = $(this);var $img = $a.find('img').first(); // 直接查找 <img> 子元素if ($img.length > 0) {$img.attr('width', '50').attr('height', '50'); // 使用 jQuery 设置属性result += $a.html();} else {result += $a.html(); // 无图片则直接返回原内容}} else {if (typeof $(this).html() === 'undefined') {result += $(this).text();} else if (jQuery().bootstrapTable === undefined || ($(this).hasClass('filterControl') !== true && $cell.parents('.detail-view').length === 0)) {result += $(this).html();}}});return result;}//----------修改图片样式--end---------------},
以下这块代码是用来调整行高
onMsoNumberFormat: function (cell, row, col) {var h = 80return !isNaN($(cell).text()) ? '\\@\';height:\''+h+'px' : '';
},
onCellHtmlData 这个方法中是用来调整图片大小,有需要的自取,也做自己记录使用