【问题标题】:Using Alasql can you replace null column with empty string使用 Alasql 可以用空字符串替换空列吗
【发布时间】:2016-12-05 22:45:26
【问题描述】:

在我的角度控制器中,我有 ExportToExcel 函数,它使用 alasql 将数据导出到 Excel,并且数据来自角度数组。 问题是数组可能包含 null 作为数据,是否可以将 null 替换为 alasql 中的空字符串

下面是函数

 ac.ExportToExcel = function () {
        var time = new Date().toJSON().slice(0, 10);
        alasql('SELECT * INTO XLSX("ExchangeReport' + time + '.xlsx",{headers:true}) FROM ? WHERE BillingPeriod = "' + ac.ExchangeReport.BillingPeriod + '" or "' + ac.ExchangeReport.BillingPeriod + '" = "" ', [ac.ExchangeDatas]);
    }

这是我的数据源

ac.ExchangeDatas = [];

来自

        ac.GetAllExchangeData = function () {
        AccountRepository.GetAllExchangeData().$promise.then(
            function (data) {
                ac.ExchangeDatas = data.result;
            },
            function (err) {
                console.log("error in GetAllExchangeData : " + err);
            }
        );
    }

excel中的数据:

【问题讨论】:

    标签: angularjs excel alasql


    【解决方案1】:
    var old = JSON.stringify($scope.achData).replace(/null/g, '""'); //convert to 
    JSON string and puts empty string in place of null values   
    var newArray = JSON.parse(old); //convert back to array  
    alasql('select * into XLSX("amar.xlsx", {headers:true}) from ?', [newArray]);
    

    【讨论】:

      【解决方案2】:

      您应该可以使用COALESCE,但您需要列出所有列,例如COALESCE(YourColumn,'') AS YourColumn,而不是*。见https://github.com/agershun/alasql/wiki/Coalesce

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-06
        相关资源
        最近更新 更多