Skip to content

Instantly share code, notes, and snippets.

@masterk63
Created July 20, 2017 18:43
Show Gist options
  • Save masterk63/14ec1dc7288144a8ddb3c12c828bf99d to your computer and use it in GitHub Desktop.
Save masterk63/14ec1dc7288144a8ddb3c12c828bf99d to your computer and use it in GitHub Desktop.
generar excel api node
exports.excel = function(req, res, next){
var nodeExcel=require('excel-export');
var conf={}; //lleva la configuarcion de las columnas y filas
arr=[]; // array donde se generan las filas
var fechaInicio = '"'+req.params.fechaInicio+'"';
var fechaFin = '"'+req.params.fechaFin+'"';
conf.cols=[{
caption:'Sl.',
type:'number',
width:3
},
{
caption:'Job',
type:'string',
width:50
},
{
caption:'Date',
type:'string',
width:15
}
];
operacion.getOperacionesPorFecha(fechaInicio,fechaFin,function(consulta){
let operaciones = consulta;
for(i=0;i <operaciones.length;i++){
idOperacion = operaciones[i].idOperacion;
apellidoProfesional = operaciones[i].apellidoProfesional;
nombreProfesional = operaciones[i].nombreProfesional;
a=[idOperacion,apellidoProfesional,nombreProfesional];
arr.push(a);
}
conf.rows=arr; // armo el excel con todos los datos.
var result=nodeExcel.execute(conf);
res.setHeader('Content-Type','application/vnd.openxmlformates');
res.setHeader("Content-Disposition","attachment;filename="+"Operaciones.xlsx");
res.end(result,'binary');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment