0

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

3
  • have you tried searching for any solutions? Commented Aug 17, 2018 at 12:30
  • @Aleksey Solovey - yeah searched a lot, added reference of link in above description.Most of them convert table data to excel in angularjs none on creating excel file as above. Commented Aug 17, 2018 at 12:32
  • github.com/SheetJS/js-xlsx ? Commented Aug 17, 2018 at 12:35

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.