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 這個方法中是用來調整圖片大小,有需要的自取,也做自己記錄使用