试过table2Excel导出,图片是可以导出,但是只要表格有合并的单元格会导致列错位
以下代码是将图片转为base64,导出的excel文件中的图片也是base64的
exportExcel:function(options = {}){
var defaults = {
id:"bootstrap-table",
type: 'excel',
fileName: 'excel数据',
mso: {
worksheetName: options.fileName || 'excel数据',
styles:[
'background-color',
'font-size',
'width',
'height',
'border',
'text-align',
'vertical-align',
'border-bottom',
'border-top',
'border-left',
'border-right'
]
},
}
var options = $.extend(defaults, options);
options.onCellData = function (cell, row, col, data) {
// check if the cell contains an image
let image = $(cell).find('img');
if (image.length > 0) {
var img = new Image();
img.src = image[0].currentSrc;
img.setAttribute("crossOrigin",'Anonymous')
// // return the image source as the cell data
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL('image/jpeg', 0.95);
return dataURL;
} else {
// return the default cell data
return data;
}
};
$('#'+options.id).tableExport(options)
},