2

首先对alasql-project 的贡献者表示高度赞扬。将我的 JSON 数据导出到 excel 文件对我有很大帮助。但是对于接下来的步骤,我需要一些有关格式化 excel 文件的帮助。

是否可以定义具有自动宽度的单元格?我需要为一列着色。

我在另一个线程中看到过一篇文章,但这在我的示例中不起作用。

这是我的代码:

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]);
};
4

1 回答 1

1

我有个好主意试试这个..

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]);
};
于 2017-02-27T12:27:55.757 回答