2

我正在使用 alasql 导出到 excel,并且我正在尝试执行如下所示的自定义标题。所有其他字段名称都很好,除非它是“动作”

function myCtrl($scope) {
$scope.exportData = function () {
    alasql('SELECT name as MY_NAME, action as MY_ACTION INTO XLSX("john.xlsx",{headers:true}) FROM ?',[$scope.items]);
};

$scope.items = [{
    name: "John Smith",
    action: "j.smith@example.com",
    dob: "1985-10-10"
}, {
    name: "Jane Smith",
    action: "jane.smith@example.com",
    dob: "1988-12-22"
}, {
    name: "Jan Smith",
    action: "jan.smith@example.com",
    dob: "2010-01-02"
}, {
    name: "Jake Smith",
    action: "jake.smith@exmaple.com",
    dob: "2009-03-21"
}, {
    name: "Josh Smith",
    action: "josh@example.com",
    dob: "2011-12-12"
}, {
    name: "Jessie Smith",
    action: "jess@example.com",
    dob: "2004-10-12"
}];
};

给了我以下错误

Error: Parse error on line 1:
...CT name as MY_NAME, action as MY_ACTION 
-----------------------^
Expecting 'LITERAL', 'BRALITERAL', 'LPAR', 'NUMBER', 'STRING', 'SHARP',     'DOLLAR', 'AT', 'COLON', 'NOT', 'PLUS', 'STAR', 'QUESTION', 'CURRENT_TIMESTAMP', 'JAVASCRIPT', 'NEW', 'CAST', 'CONVERT', 'SUM', 'COUNT', 'MIN', 'MAX', 'AVG', 'FIRST', 'LAST', 'AGGR', 'ARRAY', 'TRUE', 'FALSE', 'NSTRING', 'NULL', 'EXISTS', 'BRAQUESTION', 'CASE', 'MINUS', 'ATLBRA', 'LCUR', got 'ACTION'
at Object.parseError (alasql.min.js:3)
at Object.parse (alasql.min.js:3)
at Function.alasql.parse (alasql.min.js:3)`
4

1 回答 1

3

action 是一个 alasql 关键字。为了解决这个问题,我用 [] 包裹了动作,如下所示

"[action] AS MY_ACTION,"

这解决了这个问题

于 2015-11-19T21:21:32.193 回答