【问题标题】:Formatting the export Excel with ALASQL (AngularJS)使用 ALASQL (AngularJS) 格式化导出 Excel
【发布时间】:2016-04-04 13:54:11
【问题描述】:

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

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

我在另一个 thread 上看到过帖子,但这在我的示例中不起作用。

这是我的代码:

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

【问题讨论】:

  • 很高兴听到您喜欢图书馆。目前 AlaSQL 不支持复杂的格式化。我建议你看看 xlsx.js 库

标签: javascript angularjs export-to-excel alasql


【解决方案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]);
};

【讨论】:

  • 虽然欢迎使用此代码 sn-p,并且可能会提供一些帮助,但它会是 greatly improved if it included an explanation of howwhy 这解决了问题。请记住,您正在为将来的读者回答问题,而不仅仅是现在提问的人!请edit您的答案添加解释,并说明适用的限制和假设。
  • "rows" 是格式化特定行而不是您提到的列。您是否有任何线索来格式化特定列。
猜你喜欢
  • 1970-01-01
  • 2016-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-30
相关资源
最近更新 更多