cybergeeeek
cybergeeeek

Reputation: 430

Create a excel file dynamically using angularjs

I looked so many examples but could not find exact solution for my query in angularjs. I tried below example also but it did not work for me. Create simple xlsx (excel file ) from javascript or Jquery

I just want to create a excel with few data as shown in attached image. I need to generate the excel file on button click event using only angularjs.

enter image description here

Upvotes: 0

Views: 3740

Answers (1)

Raju Sah
Raju Sah

Reputation: 590

Use alasql.min.js & xlsx.core.min.js

<!DOCTYPE html>
<html lang="en-US" ng-app="App">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.4.9/alasql.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.4/xlsx.core.min.js"></script> 
<body>
    <div ng-controller="BnkCtrl">
        <button ng-click="saveAsXlsx()">Save As XLSX</button>
    </div>
    <script type="text/javascript">
        angular.module("App",[])
            .controller("BnkCtrl",function($scope,$http){
                $scope.test = [{Column_A:'aa',Column_B:'bb'},{Column_A:'cc',Column_B:'dd'},{Column_A:'ee',Column_B:'ff'}];
                $scope.saveAsXlsx = function () {
                alasql('SELECT * INTO XLSX("output.xlsx",{headers:true}) FROM ?',[$scope.test]);
            }
        });
    </script>
</body>

Plunk

Upvotes: 6

Related Questions