|
@ -6,99 +6,209 @@ const moment = require('moment') |
|
|
|
|
|
|
|
|
//递归创建目录 同步方法
|
|
|
//递归创建目录 同步方法
|
|
|
async function makeDir (dir) { |
|
|
async function makeDir (dir) { |
|
|
if (!fs.existsSync(dir)) { |
|
|
if (!fs.existsSync(dir)) { |
|
|
makeDir(path.dirname(dir)) |
|
|
makeDir(path.dirname(dir)) |
|
|
fs.mkdirSync(dir, function (err) { |
|
|
fs.mkdirSync(dir, function (err) { |
|
|
if (err) { |
|
|
if (err) { |
|
|
throw err |
|
|
throw err |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), exp } = {}) { |
|
|
async function gatherSheet ({ sheet_2, data = [] }) { |
|
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
|
|
|
|
|
makeDir(fileDirPath) |
|
|
// header
|
|
|
const file = new xlsx.File(); |
|
|
const headerStyle = new xlsx.Style(); |
|
|
const sheet_1 = file.addSheet('sheet_1'); |
|
|
headerStyle.align.h = 'center'; |
|
|
|
|
|
headerStyle.align.v = 'center'; |
|
|
// header
|
|
|
headerStyle.border.right = 'thin'; |
|
|
const headerStyle = new xlsx.Style(); |
|
|
headerStyle.border.rightColor = '#000000'; |
|
|
headerStyle.align.h = 'center'; |
|
|
headerStyle.border.bottom = 'thin'; |
|
|
headerStyle.align.v = 'center'; |
|
|
headerStyle.border.bottomColor = '#000000'; |
|
|
headerStyle.border.right = 'thin'; |
|
|
|
|
|
headerStyle.border.rightColor = '#000000'; |
|
|
const headerRow1 = sheet_2.addRow(); |
|
|
headerStyle.border.bottom = 'thin'; |
|
|
const indexCell1 = headerRow1.addCell(); |
|
|
headerStyle.border.bottomColor = '#000000'; |
|
|
indexCell1.value = '南昌县农村公路养护管理暨用地范围内环境整治提升工程 考核汇总表' |
|
|
|
|
|
indexCell1.style = headerStyle |
|
|
const headerRow = sheet_1.addRow(); |
|
|
indexCell1.hMerge = 12 |
|
|
const indexCell = headerRow.addCell(); |
|
|
|
|
|
indexCell.value = '序号' |
|
|
const headerRow2 = sheet_2.addRow(); |
|
|
indexCell.style = headerStyle |
|
|
const indexCell2 = headerRow2.addCell(); |
|
|
for (let h of header) { |
|
|
indexCell2.value = '责任单位' |
|
|
const cell = headerRow.addCell(); |
|
|
indexCell2.style = headerStyle |
|
|
cell.value = h.title; |
|
|
indexCell2.vMerge = 1 |
|
|
cell.style = headerStyle |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (let h of ['县道', '', '', '', '乡道', '', '', '', '村道', '', '', '',]) { |
|
|
// data
|
|
|
const cell = headerRow2.addCell(); |
|
|
const style = new xlsx.Style(); |
|
|
|
|
|
style.align.h = 'left'; |
|
|
cell.value = h; |
|
|
style.align.v = 'center'; |
|
|
cell.style = headerStyle |
|
|
style.border.right = 'thin'; |
|
|
if(h){ |
|
|
style.border.rightColor = '#000000'; |
|
|
cell.hMerge = 3 |
|
|
style.border.bottom = 'thin'; |
|
|
|
|
|
style.border.bottomColor = '#000000'; |
|
|
} |
|
|
for (let i = 0; i < data.length; i++) { |
|
|
} |
|
|
const row = sheet_1.addRow(); |
|
|
|
|
|
const indexCell = row.addCell(); |
|
|
const header = [{ |
|
|
indexCell.value = i + 1 |
|
|
key: '', |
|
|
indexCell.style = headerStyle |
|
|
title: '', |
|
|
for (let h of header) { |
|
|
},{ |
|
|
const cell = row.addCell(); |
|
|
key: 'county', |
|
|
cell.value = data[i][h.key]; |
|
|
title: '总里程', |
|
|
|
|
|
}, { |
|
|
if (exp == 'patrol' || exp == 'maintenance') { |
|
|
key: 'countyParticipate', |
|
|
if (h.key == 'projectType') { |
|
|
title: '纳入考核里程', |
|
|
let type = data[i][h.key] |
|
|
}, { |
|
|
if (type == 'road') { |
|
|
key: 'countyPresent', |
|
|
cell.value = '道路' |
|
|
title: '本次考核里程', |
|
|
} else if (type == 'bridge') { |
|
|
}, { |
|
|
cell.value = '桥梁' |
|
|
key: 'county', |
|
|
} else if (type == 'culvert') { |
|
|
title: '实际抽取比原计划多', |
|
|
cell.value = '涵洞' |
|
|
}, { |
|
|
} else if (type == 'other') { |
|
|
key: 'township', |
|
|
cell.value = '其他' |
|
|
title: '总里程', |
|
|
} |
|
|
}, { |
|
|
continue |
|
|
key: 'townshipParticipate', |
|
|
} |
|
|
title: '纳入考核里程', |
|
|
|
|
|
}, { |
|
|
if (h.key == 'reportType') { |
|
|
key: 'townshipPresent', |
|
|
let type = data[i][h.key] |
|
|
title: '本次考核里程', |
|
|
if (type == 'patrol') { |
|
|
}, { |
|
|
cell.value = '巡查' |
|
|
key: 'township', |
|
|
} else if (type == 'conserve') { |
|
|
title: '实际抽取比原计划多', |
|
|
cell.value = '养护' |
|
|
}, { |
|
|
} |
|
|
key: 'village', |
|
|
continue |
|
|
title: '总里程', |
|
|
} |
|
|
}, { |
|
|
|
|
|
key: 'villageParticipate', |
|
|
|
|
|
title: '纳入考核里程', |
|
|
|
|
|
}, { |
|
|
|
|
|
key: 'villagePresent', |
|
|
|
|
|
title: '本次考核里程', |
|
|
|
|
|
}, { |
|
|
|
|
|
key: 'village', |
|
|
|
|
|
title: '实际抽取比原计划多', |
|
|
|
|
|
},] |
|
|
|
|
|
|
|
|
|
|
|
const headerRow3 = sheet_2.addRow(); |
|
|
|
|
|
for (let h of header) { |
|
|
|
|
|
const cell = headerRow3.addCell(); |
|
|
|
|
|
cell.value = h.title; |
|
|
|
|
|
cell.style = headerStyle |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// data
|
|
|
|
|
|
// const style = new xlsx.Style();
|
|
|
|
|
|
// style.align.h = 'left';
|
|
|
|
|
|
// style.align.v = 'center';
|
|
|
|
|
|
// style.border.right = 'thin';
|
|
|
|
|
|
// style.border.rightColor = '#000000';
|
|
|
|
|
|
// style.border.bottom = 'thin';
|
|
|
|
|
|
// style.border.bottomColor = '#000000';
|
|
|
|
|
|
// for (let i = 0; i < data.length; i++) {
|
|
|
|
|
|
// const row = sheet_2.addRow();
|
|
|
|
|
|
// 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];
|
|
|
|
|
|
// cell.style = style
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function simpleExcelDown ({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), exp, gather } = {}) { |
|
|
|
|
|
const fileDirPath = path.join(__dirname, `../../downloadFiles`) |
|
|
|
|
|
makeDir(fileDirPath) |
|
|
|
|
|
const file = new xlsx.File(); |
|
|
|
|
|
const sheet_1 = file.addSheet('sheet_1'); |
|
|
|
|
|
if (gather) { |
|
|
|
|
|
const sheet_2 = file.addSheet('sheet_2'); |
|
|
|
|
|
await gatherSheet({ sheet_2, ...gather }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// header
|
|
|
|
|
|
const headerStyle = new xlsx.Style(); |
|
|
|
|
|
headerStyle.align.h = 'center'; |
|
|
|
|
|
headerStyle.align.v = 'center'; |
|
|
|
|
|
headerStyle.border.right = 'thin'; |
|
|
|
|
|
headerStyle.border.rightColor = '#000000'; |
|
|
|
|
|
headerStyle.border.bottom = 'thin'; |
|
|
|
|
|
headerStyle.border.bottomColor = '#000000'; |
|
|
|
|
|
|
|
|
|
|
|
const headerRow = sheet_1.addRow(); |
|
|
|
|
|
const indexCell = headerRow.addCell(); |
|
|
|
|
|
indexCell.value = '序号' |
|
|
|
|
|
indexCell.style = headerStyle |
|
|
|
|
|
for (let h of header) { |
|
|
|
|
|
const cell = headerRow.addCell(); |
|
|
|
|
|
cell.value = h.title; |
|
|
|
|
|
cell.style = headerStyle |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// data
|
|
|
|
|
|
const style = new xlsx.Style(); |
|
|
|
|
|
style.align.h = 'left'; |
|
|
|
|
|
style.align.v = 'center'; |
|
|
|
|
|
style.border.right = 'thin'; |
|
|
|
|
|
style.border.rightColor = '#000000'; |
|
|
|
|
|
style.border.bottom = 'thin'; |
|
|
|
|
|
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 |
|
|
|
|
|
for (let h of header) { |
|
|
|
|
|
const cell = row.addCell(); |
|
|
|
|
|
cell.value = data[i][h.key]; |
|
|
|
|
|
|
|
|
|
|
|
if (exp == 'patrol' || exp == 'maintenance') { |
|
|
|
|
|
if (h.key == 'projectType') { |
|
|
|
|
|
let type = data[i][h.key] |
|
|
|
|
|
if (type == 'road') { |
|
|
|
|
|
cell.value = '道路' |
|
|
|
|
|
} else if (type == 'bridge') { |
|
|
|
|
|
cell.value = '桥梁' |
|
|
|
|
|
} else if (type == 'culvert') { |
|
|
|
|
|
cell.value = '涵洞' |
|
|
|
|
|
} else if (type == 'other') { |
|
|
|
|
|
cell.value = '其他' |
|
|
|
|
|
} |
|
|
|
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cell.style = style |
|
|
if (h.key == 'reportType') { |
|
|
} |
|
|
let type = data[i][h.key] |
|
|
} |
|
|
if (type == 'patrol') { |
|
|
|
|
|
cell.value = '巡查' |
|
|
const savePath = path.join(fileDirPath, fileName) |
|
|
} else if (type == 'conserve') { |
|
|
await new Promise(function (resolve, reject) { |
|
|
cell.value = '养护' |
|
|
file.saveAs() |
|
|
} |
|
|
.pipe(fs.createWriteStream(savePath)) |
|
|
continue |
|
|
.on('finish', () => { |
|
|
} |
|
|
resolve() |
|
|
} |
|
|
}); |
|
|
|
|
|
}) |
|
|
cell.style = style |
|
|
return savePath |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const savePath = path.join(fileDirPath, fileName) |
|
|
|
|
|
await new Promise(function (resolve, reject) { |
|
|
|
|
|
file.saveAs() |
|
|
|
|
|
.pipe(fs.createWriteStream(savePath)) |
|
|
|
|
|
.on('finish', () => { |
|
|
|
|
|
resolve() |
|
|
|
|
|
}); |
|
|
|
|
|
}) |
|
|
|
|
|
return savePath |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { |
|
|
module.exports = { |
|
|
simpleExcelDown |
|
|
simpleExcelDown |
|
|
} |
|
|
} |