|
|
@ -19,7 +19,7 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) { |
|
|
|
async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), needIndexCell = true } = {}) { |
|
|
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
|
|
|
makeDir(fileDirPath) |
|
|
|
const file = new xlsx.File(); |
|
|
@ -35,9 +35,11 @@ module.exports = function (app, opts) { |
|
|
|
headerStyle.border.bottomColor = '#000000'; |
|
|
|
|
|
|
|
const headerRow = sheet_1.addRow(); |
|
|
|
const indexCell = headerRow.addCell(); |
|
|
|
indexCell.value = '序号' |
|
|
|
indexCell.style = headerStyle |
|
|
|
if (needIndexCell) { |
|
|
|
const indexCell = headerRow.addCell(); |
|
|
|
indexCell.value = '序号' |
|
|
|
indexCell.style = headerStyle |
|
|
|
} |
|
|
|
for (let h of header) { |
|
|
|
const cell = headerRow.addCell(); |
|
|
|
cell.value = h.title; |
|
|
@ -54,9 +56,11 @@ module.exports = function (app, opts) { |
|
|
|
style.border.bottomColor = '#000000'; |
|
|
|
for (let i = 0; i < data.length; i++) { |
|
|
|
const row = sheet_1.addRow(); |
|
|
|
const indexCell = row.addCell(); |
|
|
|
indexCell.value = i + 1 |
|
|
|
indexCell.style = headerStyle |
|
|
|
if (needIndexCell) { |
|
|
|
const indexCell = row.addCell(); |
|
|
|
indexCell.value = i + 1 |
|
|
|
indexCell.style = headerStyle |
|
|
|
} |
|
|
|
for (let h of header) { |
|
|
|
const cell = row.addCell(); |
|
|
|
cell.value = data[i][h.key] || h.defaultValue || '-'; |
|
|
|