0
String.prototype.splitCSV = function(sep) {
  for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
    if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
      if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
        foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
      } else if (x) {
        foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
      } else foo = foo.shift().split(sep).concat(foo);
    } else foo[x].replace(/""/g, '"');
  } return foo;
};

this code is convert csv string to array. my question is that how to convert xls and tsv string to array?

2
  • you need to append the javascript tag to this, also put it in proper code segments Commented Jan 15, 2014 at 19:11
  • @user3178816 The link does not work Commented Jan 31, 2015 at 21:56

1 Answer 1

1

You can look at Alasql's CSV parser, which can convert CSV and TSV strings to array:

Or you can use Alasql to load data from CSV, TSV, XLS, or XLSX files directly to JavaScript:

alasql('SELECT * FROM XLSX("mydata.xlsx")',[], function(res){ 
    // do something
});

alasql('SELECT * FROM TSV("mydata.tsv", {headers:true})',[], function(res){ 
    // do something
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.