nulltask / express-csv Goto Github PK
View Code? Open in Web Editor NEWExpress CSV provides response CSV easily to Express.
Express CSV provides response CSV easily to Express.
Having problems with line breaks, blank spaces between lines on Excel. How to solve that?
I'm using [email protected] for an old project. This library don't add .csv method to the right response object for this version of express.
express.response
and http.ServerResponse
are both available for this version, but express actually uses http.ServerResponse
. So you only add .csv method on the first object, and the test passed for that reason.
Does it work with Express 3?
It'd be great to have this as middleware which would add to res
object the csv
method.
For example:
var expressCsv = require('express-csv')
// ...
app.use(expressCsv)
// ... or only apply it to some routes ...
app.get('/some-route', expressCsv, function(req, res, next) {
res.csv([ { a: 1, b: 2 } ])
})
Thank you for this。
How to set a header row?
Hi,
Many thanks for this package - very useful.
I am using it to convert an array of objects, most come out ok, columns in the same order, but a few come out with the columns jumbled up - relative to the rest.
Looking at the code, it just iterates over the properties to convert it into an array.
Any plans to try to make it more consistent?
Perhaps look at the first object and then use that to determine the fields to use for the others. Although that assumes that they are all the same...
Cheers,
Chris
How can I change the comma for a semicolon?
This package doesn't fully work with express 4.x (haven't tested other versions). More specifically, the sending of headers and status is not working, and deprecated respectively.
Fixing this is fairly easy:
Replace this.header('Content-Type', 'text/csv');
with this.set('Content-Type', 'text/csv');
and return this.send(body, headers, status);
with:
this.set(headers);
return this.status(status).send(body);
Getting a strange output in the Excel CSV file:
[object Object]|"false"||"0"|"[object Object]"|"[object Object]"|"[object Object]"|"function () {
var self = this
, hookArgs // arguments eventually passed to the hook - are mutable
, lastArg = arguments[arguments.length-1]
, pres = this._pres[name]
, posts = this.posts[name]
, total = pres.length
, current = -1
, asyncsLeft = proto[name].numAsyncPres
, next = function () {
if (arguments[0] instanceof Error) {
return handleError(arguments[0]);
}
var args = Array.prototype.slice.call(arguments)
, currPre
, preArgs;
if (args.length && !(arguments[0] == null && typeof lastArg === 'function'))
hookArgs = args;
if (++current < total) {
currPre = pres[current]
if (currPre.isAsync && currPre.length < 2)
throw new Error(""Your pre must have next and done arguments -- e.g., function (next, done, ...)"");
if (currPre.length < 1)
throw new Error(""Your pre must have a next argument -- e.g., function (next, ...)"");
preArgs = (currPre.isAsync
? [once(next), once(asyncsDone)]
: [once(next)]).concat(hookArgs);
return currPre.apply(self, preArgs);
} else if (!proto[name].numAsyncPres) {
return done.apply(self, hookArgs);
}
}
, done = function () {
var args = Array.prototype.slice.call(arguments)
, ret, total, current, next, done, postArgs;
if (current === total) {
ret = fn.apply(self, args);
total = posts.length;
current = -1;
next = function () {
if (arguments[0] instanceof Error) {
return handleError(arguments[0]);
}
var args = Array.prototype.slice.call(arguments, 1)
, currPost
, postArgs;
if (args.length) hookArgs = args;
if (++current < total) {
currPost = posts[current]
if (currPost.length < 1)
throw new Error(""Your post must have a next argument -- e.g., function (next, ...)"");
postArgs = [once(next)].concat(hookArgs);
return currPost.apply(self, postArgs);
}
};
if (total) return next();
return ret;
}
};
if (_asyncsLeft) {
function _asyncsDone (err) {
if (err && err instanceof Error) {
return handleError(err);
}
--_asyncsLeft || _done.apply(self, hookArgs);
}
}
function handleError (err) {
if ('function' == typeof lastArg)
return lastArg(err);
if (errorCb) return errorCb.call(self, err);
throw err;
}
return _next.apply(this, arguments);
}"|"[object Object]"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.