Created
July 20, 2017 18:43
-
-
Save masterk63/14ec1dc7288144a8ddb3c12c828bf99d to your computer and use it in GitHub Desktop.
generar excel api node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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