Answer the question
In order to leave comments, you need to log in
How to export data to excel from database?
I am using the excel4node library .
I want to export data to excel from a database. So far, I'm only trying to do this by exporting certain data by date. In general, when exporting, Excel is created, but there is not a single record.
var xl = require('excel4node')
const db = require('../config/db.config.js')
const Report = db.report
var wb = new xl.Workbook()
var ws = wb.addWorksheet('Отчет');
var style = wb.createStyle({
font: {
color: '#000000',
size: 12
}
});
module.exports.getexceldata = async function(req, res) {
try {
await Report.findAll({
where: {
report_date: req.params.report_date
}
})
ws.cell(1,1).string({name: req.body.name}).style(style)
wb.write('Excel.xlsx');
res.download('\Excel.xlsx');
} catch(e) {
errorHandler(res, e)
}
}
ws.cell(1,1).string({name: req.body.name}).style(style)
const db = require('../config/db.config.js')
const Report = db.report
Answer the question
In order to leave comments, you need to log in
ws.cell(1,1).string({name: req.body.name}).style(style)
var dataForWrite = Str(результат запроса);
ws.cell(1,1).string(dataForWrite).style(style);
res.download('\Excel.xlsx');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question