user3440015
user3440015

Reputation: 43

Select INTO Array or Object

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?

Upvotes: 1

Views: 1097

Answers (1)

agershun
agershun

Reputation: 4107

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.

Upvotes: 1

Related Questions