var workbook = new ExcelJS.Workbook();
workbook.creator = 'Me';
workbook.lastModifiedBy = 'Her';
workbook.created = new Date(1985, 8, 30);
workbook.modified = new Date();
workbook.lastPrinted = new Date(2016, 9, 27);
// 创建带有红色标签颜色的工作表
var sheet = workbook.addWorksheet('MySheet', {properties: {tabColor: {argb: 'FFC0000'}}});
sheet.mergeCells('A1:C1');
sheet.getCell('A1').value = '这是文档正标题';
sheet.getCell('A1').font = {
name: 'Comic Sans MS',
family: 4,
size: 36,
bold: true
};
sheet.getCell('A1').alignment = { vertical: 'middle', horizontal: 'center' };
sheet.columns = [
{ width: 31 },
{ width: 32 },
{ width: 33 }
];
// 生成columns
var columns = [];
data.tableHeader.map(item => {
columns.push({
name: item.label
})
})
// 生成rows
let rows = [];
data.tableData.map(item => {
let arr = [];
data.tableHeader.map(sub => {
arr.push(item[sub.prop] ? item[sub.prop] : '')
})
rows.push(arr);
})
sheet.addTable({
name: 'MyTestTable',
ref: 'A2', // 表格左上角的位置
headerRow: true,
totalsRow: false,
style: {
theme: 'TableStyleLight1',
showRowStripes: true, //单双行
},
columns: columns,
rows: rows,
});