angular8 导出excel文件
angular

package
1、xlsx
npm install xlsx --save
2、file-saver
npm install file-saver --save
npm install @types/file-saver --save
3、实现导出多个sheet的数据
exportExcel() {
import("xlsx").then(xlsx => {
// const worksheet = xlsx.utils.json_to_sheet(this.getCars());
console.log(this.BeautifuleValue);
var all = [
[],
[],
[]
];
this.BeautifuleValue.districtBeautifyAdjustedValue.forEach(element => {
all[0].push(
{
‘区县‘: this.districtName[element.customer],
‘美化系数‘: element.coefficient,
‘美化值‘: element.beautifyValue
}
);
});
this.BeautifuleValue.platBeautifyAdjustedValue.forEach(element => {
all[1].push(
{
‘平台‘: this.platName[element.plat],
‘美化系数‘: element.coefficient,
‘美化值‘: element.beautifyValue
}
);
});
this.BeautifuleValue.industryBeautifyAdjustedValue.forEach(element => {
all[2].push(
{
‘行业‘: element.industry,
‘美化系数‘: element.coefficient,
‘美化值‘: element.beautifyValue
}
);
});
const oneSheet = xlsx.utils.json_to_sheet(all[0]);
const twoSheet = xlsx.utils.json_to_sheet(all[1]);
const threeSheet = xlsx.utils.json_to_sheet(all[2]);
const workbook = { Sheets: { ‘区县‘: oneSheet, ‘平台‘: twoSheet, ‘行业‘: threeSheet }, SheetNames: [‘区县‘, ‘平台‘, ‘行业‘] };
const excelBuffer: any = xlsx.write(workbook, { bookType: ‘xlsx‘, type: ‘array‘ });
this.saveAsExcelFile(excelBuffer, "美化值");
});
}
saveAsExcelFile(buffer: any, fileName: string): void {
import("file-saver").then(FileSaver => {
let EXCEL_TYPE = ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8‘;
let EXCEL_EXTENSION = ‘.xlsx‘;
const data: Blob = new Blob([buffer], {
type: EXCEL_TYPE
});
FileSaver.saveAs(data, fileName + ‘_export_‘ + new Date().getTime() + EXCEL_EXTENSION);
});
} 相关推荐
wikiwater 2020-10-27
IdeaElements 2020-08-19
Sophiego 2020-08-16
Kakoola 2020-08-01
Kakoola 2020-07-29
ELEMENTS爱乐冬雨 2020-07-18
ELEMENTS爱乐小超 2020-07-04
ELEMENTS爱乐小超 2020-07-04
Kakoola 2020-06-28
Feastaw 2020-06-18
Wmeng0 2020-06-14
ELEMENTS爱乐冬雨 2020-06-14
云之高水之远 2020-06-14
哈喽elements 2020-06-14
Feastaw 2020-06-11