0

I am little confused to give styling for excel rows while exporting the data using alasql. Below is the code that I am working on

$scope.exportData = function () {

var mystyle = {
            sheetid: 'Test_sheet',
            headers: true,
            column: {
                style:'font-size:18px;background:green'
            },
            columns: [
                {columnid:'field1', width:120},
                {columnid:'field2', width:200},
                {columnid:'field3', width:350},
                {columnid:'field4', width:100},
            ],
            row: {

            },
            rows: {

            },
            cells: {

            }
        };

        alasql('SELECT field1,field2,field3,field4,field5 INTO XLS("Test.xls",?) FROM ?',[mystyle, $scope.data.results]);

};

Here, based on field5 value, I wanted to assign the background color of the entire row while exporting the data to excel sheet. Any idea how to modify the 'mystyle' variable?

newbie
  • 1,282
  • 3
  • 20
  • 43

2 Answers2

2

Use xlsxsml in alasql

  var mystyle = {
            headers: true,
            column: { style: { Font: { Bold: "1" } } },
            rows: { 1: { style: { Font: { Color: "#FF0077" } } } },
            cells: {
                1: {
                    1: {
                        style: { Font: { Color: "#00FFFF" } }
                    }
                }
            }
        };

alasql('SELECT field1,field2,field3,field4,field5 INTO XLSXML("Test.xls",?) FROM ?',[mystyle, $scope.data.results]);
mathiasrw
  • 610
  • 4
  • 10
  • @mathiasrw how to give a color to all cell based on certain condition. For eg: if age is less than 18 then only highlight all those cell. Is this even possible? – Alvin Jun 13 '18 at 16:26
0

For Background color u have to use the property Interior with sub property Patter: "solid" to get the desired effect

Example

var mystyle = { headers:true, column: { style:{ Font:{ Color:"#FFFFFF" }, Interior:{ Color:"#4F81BD", Pattern:"Solid" }, Alignment:{ Horizontal:"Center" }}} };