1

I`m trying to set a result query into an array or JSON object using ALASQL:

var resdata2 = [ { A: "test", B: "testB" } ]; // Destination array

// Select first and second column values from xlxs
alasql('select A,B into ? from xlsx("gohan.xlsx")', [resdata2]); 

console.log(resdata2);                        // Shows one object for xlsx line!
console.log(resdata2.length);                 // Shows length of 1 only

$.each(resdata2,function(idx, obj) {
    console.log(obj.A);                       // Shows only 'test' 
    console.log(obj.B);                       // Shows only 'testB'
});

The spreadsheet has 18 lines which appear in the first console.log(), however in second console.log() and in each function, it shows only first line "Test" and "testB".

Any ideas to show all lines?

3
  • Are you testing SELECT...INTO? Otherwise I'd drop it and use var result = alasql('SELECT A,B FROM xlsx("gohan.xlsx")'); Commented Nov 24, 2015 at 13:49
  • it returns to me result as undefined. var result = alasql('SELECT A,B FROM xlsx("gohan.xlsx")'); console.log(result) //undefined Commented Nov 24, 2015 at 15:07
  • Have a look at jsfiddle.net/ko54Ltv5 and look at how A, B and C is not printed in order as the call is async Commented May 3, 2016 at 11:52

1 Answer 1

1

Probably you nee to use callback interface:

var resdata2;
alasql('select A,B from xlsx("gohan.xlsx")', [], function(data) {
    resdata2 = data;
}); 

Here you need to use AlaSQL's callback interface, because XLSX() function is async.

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.