参考 https://github.com/hhurz/tableExport.jquery.plugin#options
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {$(document).ready(function(){$('#table').bootstrapTable('refreshOptions', {exportOptions: {onMsoNumberFormat: DoOnMsoNumberFormat}});});function DoOnMsoNumberFormat(cell, row, col) {return (row > 0 ) ? '\\@' : '';}var Controller = {index: function () {// 初始化表格参数配置Table.api.init({extend: {index_url: 'register/index' + location.search,add_url: 'register/add',edit_url: 'register/edit',del_url: 'register/del',multi_url: 'register/multi',table: 'register',},//fastadminexportTypes: ['json', 'xml', 'csv', 'txt', 'doc', 'excel'],exportOptions: {fileName: 'export_' + Moment().format("YYYY-MM-DD"), //导出名称ignoreColumn: [0, 'operate'], //不导出字段ignoreRow: [],csvSeparator: "----",//文本分割htmlContent: true,onMsoNumberFormat: DoOnMsoNumberFormat},//fastadmin});var table = $("#table");// 初始化表格table.bootstrapTable({url: $.fn.bootstrapTable.defaults.extend.index_url,pk: 'id',sortName: 'id',exportOptions: {fileName: 'export_' + Moment().format("YYYY-MM-DD"), // 原方法 定义生成的文件名ignoreColumn: [0, 'operate'] ,// 原方法 默认跳过输出多选框和操作列// FA专家 大饼博士代码htmlContent: true,mso:{onMsoNumberFormat:function(cell,row,col,htmlData){if ($(cell).children().children().hasClass('img-center')) {var img=$(cell).children().children();var src =img.attr('src');return src;}return !isNaN($(cell).text())?'\\@':'';},},onCellHtmlData:function (cell,row,col){console.log(cell.html())if ($(cell).children().children().hasClass('img-center')) {console.log(111)var img=$(cell).children().children();var src =img.attr('src');if (src.indexOf('http') === -1) {img.attr('src', window.location.origin + src);}img.attr("width", "100").attr("height", "100").attr('class', '');//result += '<div>' + $(this).get(0).outerHTML + '</div>';result = '<div>' + img.parent().html()+ '</div>';return result;}else {return $(cell).text();}}},columns: [[{checkbox: true},{field: 'id', title: __('Id')},{field: 'name', title: __('Name')},{field: 'phone', title: __('Phone')},{field: 'email', title: __('Email')},{field: 'identity_card', title: __('Identity_card')},{field: 'unit', title: __('Unit')},{field: 'form_post', title: __('Form_post')},{field: 'type_academic', title: __('Type_academic'), searchList: {"1":__('Type_academic 1'),"2":__('Type_academic 2')}, formatter: Table.api.formatter.normal},{field: 'price', title: __('Price'), operate:'BETWEEN'},{field: 'apply', title: __('报告名')},{field: 'type_pay', title: __('Type_pay'), searchList: {"1":__('Type_pay 1'),"2":__('Type_pay 2'),"3":__('Type_pay 3')}, formatter: Table.api.formatter.normal},{field: 'remark', title: __('Remark')},{field: 'person_changed', title: __('人员类型'),searchList: {"1":__('正式代表'),"2":__('学生代表')},},{field: 'student_card', title: __('学生证'),operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}]]});// 为表格绑定事件Table.api.bindevent(table);},add: function () {Controller.api.bindevent();},edit: function () {Controller.api.bindevent();},api: {bindevent: function () {Form.api.bindevent($("form[role=form]"));console.log("加载完成")}}};return Controller;
});
exportOptions:参数如下
csvEnclosure: '"'
csvSeparator: ','
csvUseBOM: true
date: html: 'dd/mm/yyyy'
exportHiddenCells: false
fileName: 'tableExport'
htmlContent: false
htmlHyperlink: 'content'
ignoreColumn: []
ignoreRow: []
jsonScope: 'all'
jspdf: orientation: 'p'unit:'pt'format: 'a4'margins: left: 20right: 10top: 10bottom: 10onDocCreated: nullautotable: styles: cellPadding: 2rowHeight: 12fontSize: 8fillColor: 255textColor: 50fontStyle: 'normal'overflow: 'ellipsize'halign: 'inherit'valign: 'middle'headerStyles: fillColor: [52, 73, 94]textColor: 255fontStyle: 'bold'halign: 'inherit'valign: 'middle'alternateRowStyles: fillColor: 245tableExport: doc: nullonAfterAutotable: nullonBeforeAutotable: nullonAutotableText: nullonTable: nulloutputImages: true
mso: fileFormat: 'xlshtml'onMsoNumberFormat: nullpageFormat: 'a4'pageOrientation: 'portrait'rtl: falsestyles: []worksheetName: ''xlsx: formatId: date: 14numbers: 2currency: 164format: currency: '$#,##0.00;[Red]-$#,##0.00'onHyperlink: null
numbers: html: decimalMark: '.'thousandsSeparator: ','output: decimalMark: '.'thousandsSeparator: ','
onAfterSaveToFile: null
onBeforeSaveToFile: null
onCellData: null
onCellHtmlData: null
onCellHtmlHyperlink: null
onIgnoreRow: null
onTableExportBegin: null
onTableExportEnd: null
outputMode: 'file'
pdfmake: enabled: falsedocDefinition: pageSize: 'A4'pageOrientation: 'portrait'styles: header: background: '#34495E'color: '#FFFFFF'bold: truealignment: 'center'fillColor: '#34495E'alternateRow: fillColor: '#f5f5f5'defaultStyle: color: '#000000'fontSize: 8font: 'Roboto'fonts: {}widths: '*'
preserve: leadingWS: falsetrailingWS: false
preventInjection: true
sql: tableEnclosure: '`'columnEnclosure: '`'
tbodySelector: 'tr'
tfootSelector: 'tr'
theadSelector: 'tr'
tableName: 'myTableName'
type: 'csv'