【问题标题】:export multiple json objects to xlsx file using alasql使用 alasql 将多个 json 对象导出到 xlsx 文件
【发布时间】:2016-02-21 21:21:38
【问题描述】:

第一次使用 alasql 和一般的 sql,但是尝试将多个 json 对象导出到 xlsx 文件 我正在使用

  alasql('SELECT * INTO XLSX("Report.xlsx",{headers:true}) FROM ?', [$scope.children, $scope.answer, $scope.optional, $scope.user]);

仅适用于数组 ($scope.children) 中的第一个对象,但不会显示这些对象的其余部分。 有什么线索我可以将所有这些对象添加到一个表中。

我也尝试将所有对象合并为一个对象,但没有奏效,我只得到正确的表格标题,但它没有显示正确的数据,它只在表格单元格内显示(对象对象)。

【问题讨论】:

  • insert into xlsx 不起作用?
  • 我不明白你的意思?报告文件尚不存在

标签: javascript json excel xlsx alasql


【解决方案1】:

您期望 Excel 文件中的结果是什么?

如果这是多个工作表文件,每个数组都有不同的工作表,则应该是

 var opts = [{sheetid:'Children'},{sheetid:'Answer'}, 
    {sheetid:'Optional'},{sheetid:'User'}];

 alasql('SELECT INTO XLSX("Report.xlsx") FROM ?', 
      [opts,[$scope.children, $scope.answer, $scope.optional, $scope.user]]);

如果要将所有这些数组合并为一个数组,则需要先准备好,例如:

var arr = [];
$scope.children.forEach(function(ch,idx){
    arr.push({child:$scope.children[idx], answer:$scope.answer[idx],
                  optional:$scope.optional[idx],$scope.user[idx]
    });
});

alasql('SELECT * INTO XLSX("Report.xlsx") FROM ?',[arr]);

如果您可以提供有关 $scope.children、$scope.answer 和其他对象(或数组)结构的更多详细信息,我可以根据您的需要调整答案。

【讨论】:

  • $scope.answer,$scope.optional, $scope.user 是简单的 json 对象,但 $scope.children 是对象数组:$scope.children = [{ firstName:'' ", lastName:" ", isStudent: " "},{ firstName:'' ", lastName:" ", isStudent: " "}] 而这个对象是 xlsx 文件中显示的对象作为[对象对象]
猜你喜欢
  • 2016-11-10
  • 1970-01-01
  • 1970-01-01
  • 2014-12-26
  • 2016-02-20
  • 2017-07-14
  • 1970-01-01
  • 2017-10-10
  • 1970-01-01
相关资源
最近更新 更多