5 changed files with 557 additions and 514 deletions
@ -0,0 +1,39 @@ |
|||||
|
'use strict'; |
||||
|
const xlsx = require('better-xlsx'); |
||||
|
const path = require('path') |
||||
|
const moment = require('moment') |
||||
|
|
||||
|
module.exports = function (app, opts) { |
||||
|
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) { |
||||
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
||||
|
const file = new xlsx.File(); |
||||
|
const sheet_1 = file.addSheet('sheet_1'); |
||||
|
|
||||
|
// header
|
||||
|
const headerRow = sheet.addRow(); |
||||
|
for (let h of header) { |
||||
|
const cell = headerRow.addCell(); |
||||
|
cell.value = h.title; |
||||
|
|
||||
|
//设置文本在单元格内水平垂直居中
|
||||
|
cell.style.align.h = 'center'; |
||||
|
cell.style.align.v = 'center'; |
||||
|
|
||||
|
// border(cell, 0, 0, 1, 0)
|
||||
|
} |
||||
|
|
||||
|
const savePath = path.join(fileDirPath, fileName + '.xlsx') |
||||
|
await new Promise(function (resolve, reject) { |
||||
|
file.saveAs() |
||||
|
.pipe(fs.createWriteStream(savePath)) |
||||
|
.on('finish', () => { |
||||
|
resolve() |
||||
|
}); |
||||
|
}) |
||||
|
return savePath |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
simpleExcelDown |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
Loading…
Reference in new issue