Created
March 12, 2021 05:36
-
-
Save diegofcornejo/ed2f1e4f3336399e2a22d02cee9496dd to your computer and use it in GitHub Desktop.
Generate charts inside xlsx doc with 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
var express = require('express'); | |
var bodyParser = require('body-parser'); | |
var app = express(); | |
var fs = require("fs"); | |
//=================================== | |
var XLSXChart = require("xlsx-chart"); | |
var xlsxChart = new XLSXChart(); | |
var opts = { | |
chart: "radar", | |
titles: [ | |
"Price" | |
], | |
fields: [ | |
"Contract & Contractor Management", | |
"Quality Management in Construction", | |
"CSV & Sustainability", | |
"Logistic Management", | |
"Safety & Environmental", | |
"Operative Construction Management" | |
], | |
data: { | |
"Price": { | |
"Contract & Contractor Management": 5, | |
"Quality Management in Construction": 53, | |
"CSV & Sustainability": 95, | |
"Logistic Management": 15, | |
"Safety & Environmental": 40, | |
"Operative Construction Management": 50 | |
} | |
}, | |
chartTitle: "HPO ENEL" | |
}; | |
//==================================================================== | |
app.use(bodyParser.json({ | |
limit: '50mb' | |
})); // parse application/vnd.api+json as json | |
app.use(bodyParser.urlencoded({ | |
limit: '50mb', | |
extended: true, | |
parameterLimit: 50000 | |
})); // parse application/x-www-form-urlencoded | |
app.use(function (req, res, next) { | |
res.header("Access-Control-Allow-Origin", "*"); | |
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS'); | |
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | |
next(); | |
}); | |
app.set('port', process.env.PORT || 4000); | |
var server = app.listen(app.get('port'), function () { | |
console.log('Express server listening on port ' + server.address().port); | |
xlsxChart.generate(opts, function (err, data) { | |
var filename = "radar_"+Date.now()+".xlsx"; | |
if (err) { | |
console.error(err); | |
} else { | |
fs.writeFileSync(filename, data); | |
console.log(filename+" created."); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment