table.bootstrapTable({
...
showExport: true,
exportTypes:['excel'],
exportDataType: "all", //可用值 all 当前搜索条件下所有的可见列的数据 selected 选中行的数据 basic 当前分页下的数据
exportOptions: {
fileName: '自定义导出文件名'+ Moment().format("YYYY-MM-DD"),
htmlContent: true,
ignoreColumn: [0, -1], // 忽略第一列和最后一列
// ignoreColumn: { ignoreColumn: [0, 'operate', 'avatar'] //默认不导出第一列(checkbox)与操作(operate)列 },
mso: {
//修复导出数字不显示为科学计数法
onMsoNumberFormat: function (cell, row, col) {
return !isNaN($(cell).text())?'\\@':'';
}
},
onBeforeSaveToFile: function (data, fileName, type, charset, encoding, bom) {
return $.fn.bootstrapTable.defaults.extend.savestatus;
},
// 处理导出图片
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("img")) {
var src = $(this).attr('src');
if (src.indexOf('http') === -1) {
$(this).attr('src', window.location.origin + src);
}
$(this).attr("width", "100").attr("height", "100").attr('class', '');
result += '<div>' + $(this).get(0).outerHTML + '</div>';
} 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;
},
onCellHtmlHyperlink: function ($cell, rowIndex, colIndex, href, 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("img")) {
var src = $(this).attr('src');
if (src.indexOf('http') === -1) {
$(this).attr('src', window.location.origin + src);
}
$(this).attr("width", "40").attr("height", "40").attr('class', '');
result += '<div>' + $(this).get(0).outerHTML + '</div>';
} 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;
}
},
...
)
“@” 强制为文本格式
“0” 数字 无小数
“0.000” 数字 三位小数
“0%” 百分比 无小数
“Percent” 百分比 两位小数