Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shortid: request.template.baseXlsxTemplate.shortid
}, request)
if (!docs.length) {
throw reporter.createError(`Unable to find xlsx template with shortid ${request.template.baseXlsxTemplate.shortid}`, {
statusCode: 404
})
}
xlsxTemplateBuf = docs[0].contentRaw
}
tableXlsxBuf = Buffer.concat(await toArrayAsync(response.stream))
const [templateWorkbook, tableWorkbook] = await Promise.all([
XlsxPopulate.fromDataAsync(xlsxTemplateBuf),
XlsxPopulate.fromDataAsync(tableXlsxBuf)
])
const sheetsInTableWorkbook = tableWorkbook.sheets()
sheetsInTableWorkbook.forEach((sheet) => {
let oldSheet
if (templateWorkbook.sheet(sheet.name()) != null) {
if (templateWorkbook.sheets().length === 1) {
oldSheet = `${sheet.name()}-old`
// the workbook can not have empty sheets so we need to rename the only sheet first and then delete it
templateWorkbook.sheet(sheet.name()).name(oldSheet)
} else {
templateWorkbook.deleteSheet(sheet.name())
}
}, request)
if (!docs.length) {
throw reporter.createError(`Unable to find xlsx template with shortid ${request.template.baseXlsxTemplate.shortid}`, {
statusCode: 404
})
}
xlsxTemplateBuf = docs[0].contentRaw
}
tableXlsxBuf = Buffer.concat(await toArrayAsync(response.stream))
const [templateWorkbook, tableWorkbook] = await Promise.all([
XlsxPopulate.fromDataAsync(xlsxTemplateBuf),
XlsxPopulate.fromDataAsync(tableXlsxBuf)
])
const sheetsInTableWorkbook = tableWorkbook.sheets()
sheetsInTableWorkbook.forEach((sheet) => {
let oldSheet
if (templateWorkbook.sheet(sheet.name()) != null) {
if (templateWorkbook.sheets().length === 1) {
oldSheet = `${sheet.name()}-old`
// the workbook can not have empty sheets so we need to rename the only sheet first and then delete it
templateWorkbook.sheet(sheet.name()).name(oldSheet)
} else {
templateWorkbook.deleteSheet(sheet.name())
}
}