1

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

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

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

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

4

1 回答 1

0

您期望 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 和其他对象(或数组)的结构的更多详细信息,我可以根据您的需要调整答案。

于 2016-02-22T08:45:44.213 回答