2

Firstly a big compliment on the contributors of the alasql-project. It helps me a lot to export my JSON data to excel file. But for the next steps, I need some help about formatting the excel file.

Is it possible to define the cells with an automatically width? And I need to color one column.

I have been seen a post in an other thread, but this didn't work in my example.

Here is my code:

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

vm.btnExport = function () {
        alasql('shortcode AS Short_Code, \ ' + 
                'fname AS Fullname, \ ' +
                'INTO XLSX("test.xlsx", ?) FROM ?', [opts, vm.list]);
};
Community
  • 1
  • 1
yuro
  • 2,189
  • 6
  • 40
  • 76
  • Great to hear you like the library. At the moment AlaSQL does not support complex formatting. I suggest you take a look at the xlsx.js library – mathiasrw Apr 29 '16 at 20:14

1 Answers1

1

I have got great idea try with this..

var opts = {
    sheetid : ' Report',
    headers : true,
    style : 'font-size:25px',
    caption : {
        title : 'Report',
    },
    columns : [
        {
            title : "column Name",
            columnid : "key value"
        }
    ],
    rows: {
        //for putting background color in particular column
        0: {
            cell: {
                style: 'font-size:17px;background:#115ea2;color:white;font-weight:bold'
            }
        },
    },
    cells: {
        //if you want to put style in particular cell 
        1: {
            5: {
                style: 'font-size:20px;background:#115ea2 ;color:white;font-weight:bold;text-align:right',
                value: function(value){return value;}
            },
        }
    }
};

vm.btnExport = function () {
        alasql('shortcode AS Short_Code, \ ' + 
                'fname AS Fullname, \ ' +
                'INTO XLSX("test.xlsx", ?) FROM ?', [opts, vm.list]);
};
armstrhb
  • 4,054
  • 3
  • 20
  • 28
  • Whilst this code snippet is welcome, and may provide some help, it would be [greatly improved if it included an explanation](//meta.stackexchange.com/q/114762) of *how* and *why* this solves the problem. Remember that you are answering the question for readers in the future, not just the person asking now! Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Feb 27 '17 at 12:52
  • "rows" is to format a particular row instead of a column as you have mentioned. Do you have any clue to format a particular column. – Jyoti Kumar Apr 24 '18 at 11:49