Search code examples
angularjsalasql

Is it possible to add Excel sheets using alasql in angularJs


I want to export data of two different arrays in a single excel document. The data of two different arrays should be exported in two different sheets.

$scope.details= {
              "boys": [
                       {"name":"Jeet", "age":25},
                       {"name":"John", "age":24}
                      ],
              "girls":[
                       {"name":"Gita", "age":25},
                       {"name":"Sima", "age":24}
                      ]
               }

Now if I write

alasql('SELECT * INTO XLSX("Details.xlsx",{headers:true}) FROM ?',[$scope.details.boys]);

It will export the details of boys only in the excel sheet. How do I export for both boys and girls in a single excel document in two different sheets? Thanks in advance.


Solution

  • You need to create two different sheets with two different arrays holding boys and girls information and then export like below

    $scope.details= {
                  "boys": [
                           {"name":"Jeet", "age":25},
                           {"name":"John", "age":24}
                          ],
                  "girls":[
                           {"name":"Gita", "age":25},
                           {"name":"Sima", "age":24}
                          ]
                   }
    var boys = $scope.details.boys;
    var girls = $scope.details.girls;
    var opts = [{ sheetid: 'Boys', headers: true }, { sheetid: 'Girls', headers: true }];
    alasql('SELECT INTO XLSX("Details.xlsx",?) FROM ?', [opts, [boys, girls]]);