I am using UI-Grid for creating a grid view on my angular application. UI-Grid provides exporting the filtered and full grid data into csv or pdf format. But I need to export the data into excel.
我正在使用UI-Grid在我的角度应用程序上创建网格视图。 UI-Grid提供将过滤的和完整的网格数据导出为csv或pdf格式。但我需要将数据导出到excel中。
I have used earlier Alasql to export grid data but there I was using ng-repeat to generate the grid.
我使用早期的Alasql导出网格数据,但我使用ng-repeat生成网格。
Here Ui-grid directives takes care of generating the grid and by using simple methods exposed by UI-Grid directive we can export data. Just wanted to know if someone has tried exporting the data into excel.
这里的Ui-grid指令负责生成网格,并且通过使用UI-Grid指令公开的简单方法,我们可以导出数据。只是想知道是否有人尝试将数据导出到excel中。
Not sharing the code as I am using the same code as provided by UI-Grid tutorials and its working for me, just that i need export in excel file.
不共享代码,因为我正在使用UI-Grid教程提供的相同代码及其为我工作,只是我需要在excel文件中导出。
1 个解决方案
#1
2
I'm working at an app using ui-grid too, to export data to xlsx I had used alasql like this :
我正在使用ui-grid的应用程序工作,将数据导出到xlsx我曾经使用过像这样的alasql:
$scope.exportXLS = function exportXLS() {
alasql.promise('SELECT * INTO XLSX("data.xlsx",{headers:true}) FROM ?',[$scope.gridOptions.data])
.then(function(data){
console.log('Data saved as XLSX');
}).catch(function(err){
console.log('Error:', err);
});
};
and to export just the filterd data I get it using gridApi like this:
并且只导出过滤后的数据,我使用gridApi得到它,如下所示:
$scope.filteredData =$scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
then map the entity field from each object in returned array to a new array , I done that using map function from underscore lib.
然后将实体字段从返回数组中的每个对象映射到一个新数组,我使用下划线lib中的map函数完成。
entities = _.map($scope.filteredData, 'entity');
and finally replace '$scope.gridOptions.data' with 'entities' in function above.
最后在上面的函数中用'entities'替换'$ scope.gridOptions.data'。
#1
2
I'm working at an app using ui-grid too, to export data to xlsx I had used alasql like this :
我正在使用ui-grid的应用程序工作,将数据导出到xlsx我曾经使用过像这样的alasql:
$scope.exportXLS = function exportXLS() {
alasql.promise('SELECT * INTO XLSX("data.xlsx",{headers:true}) FROM ?',[$scope.gridOptions.data])
.then(function(data){
console.log('Data saved as XLSX');
}).catch(function(err){
console.log('Error:', err);
});
};
and to export just the filterd data I get it using gridApi like this:
并且只导出过滤后的数据,我使用gridApi得到它,如下所示:
$scope.filteredData =$scope.gridApi.core.getVisibleRows($scope.gridApi.grid);
then map the entity field from each object in returned array to a new array , I done that using map function from underscore lib.
然后将实体字段从返回数组中的每个对象映射到一个新数组,我使用下划线lib中的map函数完成。
entities = _.map($scope.filteredData, 'entity');
and finally replace '$scope.gridOptions.data' with 'entities' in function above.
最后在上面的函数中用'entities'替换'$ scope.gridOptions.data'。