How to customize custom header names using ALASQL and XLSX

I am exporting some tables to excel using angular, alasql and xlsx. I use it like this:

var options = {
    headers: true,
    sheetid: 'users',
    columns: [{
      columnid: 'a',
      title: 'Username'
    }, {
      columnid: 'b',
      title: 'First name'
    }, {
      columnid: 'c',
      title: 'Last name'
    }]
  };

alasql('SELECT * INTO XLSX("test.xlsx", ?) FROM ?', [options, $scope.users]);

      

I expected the columnns parameter to customize my table headers. But he doesn't.

Any clue why?

+3


source to share


2 answers


I was able to customize the headers using simple SQL:

alasql('SELECT firstName AS FirstName INTO XLSX("test.xlsx", ?) FROM ?', [options, $scope.users]);

      



It worked, the title for firstName will be FirstName.

+3


source


Sometimes you want to use Headers including spaces (Separated) or ... using Headers that are Reserved (Deleted), in both cases you can use [] like this:



alasql('SELECT firstName AS FirstName, [Deleted] AS [Erased], Separated AS [Separated By] INTO XLSX("test.xlsx", ?) FROM ?', [options, $scope.users]);

      

+8


source







All Articles