1

first time using alasql, and sql in general, however trying to export multiple json objects to xlsx file i am using

  alasql('SELECT * INTO XLSX("Report.xlsx",{headers:true}) FROM ?', [$scope.children, $scope.answer, $scope.optional, $scope.user]);

which works fine only for first object in array ($scope.children), but never show up rest of these objects. Is there any clue how i can add all of these object to only one table.

also i tried to merge all objects to only one object, but didn't work, i only get table header right, however it didn't show the right data it only shows (Object object) inside table cells.

Kero
  • 1,924
  • 5
  • 33
  • 53

1 Answers1

0

What result do you expect in the Excel file?

If this is multiple sheet file with different sheets for each array it should be

 var opts = [{sheetid:'Children'},{sheetid:'Answer'}, 
    {sheetid:'Optional'},{sheetid:'User'}];

 alasql('SELECT INTO XLSX("Report.xlsx") FROM ?', 
      [opts,[$scope.children, $scope.answer, $scope.optional, $scope.user]]);

In case if you want to merge all these arrays into one array, you need to prepare it first, for example:

var arr = [];
$scope.children.forEach(function(ch,idx){
    arr.push({child:$scope.children[idx], answer:$scope.answer[idx],
                  optional:$scope.optional[idx],$scope.user[idx]
    });
});

alasql('SELECT * INTO XLSX("Report.xlsx") FROM ?',[arr]);

If you can provide more details about the structure of $scope.children, $scope.answer, and other objects (or arrays) I can adjust the answer to your needs.

agershun
  • 4,077
  • 38
  • 41
  • $scope.answer,$scope.optional, $scope.user are simple json object, but $scope.children is array of objects : `$scope.children = [{ firstName:'' ", lastName:" ", isStudent: " "},{ firstName:'' ", lastName:" ", isStudent: " "}]` and this object is the one show in xlsx file as [Object object ] – Kero Feb 22 '16 at 18:51