后端前向端提供的base64位格式的图片在前端能正常显示
现在将其导入到excel 中 ,代码如下
const wb = XLSX.utils.book_new()
exportExcel(){
const headers = ['图片', '产品名称', '产品参数', '品牌', '型号', '单位', '单价', '产地', '分类', '供应商', '报告'];
const data = this.multipleSelection.map(row => {
return [this.base64ToBlob(row.img), row.name, row.para, row.brand, row.model, row.unit, row.price, row.place, row.category, row.supplier, row.report];
});
const sheet = XLSX.utils.aoa_to_sheet([headers, ...data]);
XLSX.utils.book_append_sheet(wb, sheet, 'table1');
const wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: true,
type: 'array'
});
const blob = new Blob([wbout], {
//type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8" //换成这个也不行效果一样
type:"application/vnd.ms-excel"
});
FileSaver.saveAs(blob, '产品信息表.xlsx');
},
base64ToBlob(base64) {
const bstr = atob(base64);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
const blob = new Blob([u8arr], {
type: 'image/png'
});
//return blob;
return URL.createObjectURL(blob);
},
结果 excel 表格中图片那栏显示为
图片
**blob:http://localhost:8080/5608fcc5-6f8f-4ed3-9405-cb4968a211fc **
请问这是怎么一回事,如何让其在excel中显示成图片
您好可以参考线这篇文章,您的这个插件应该不支持导出现成的图片,需要更换插件
希望能帮助到你http://t.csdn.cn/VjgxQ