You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello all,
i coded controller in angularjs to to call "$scope.readExcel" after upload xlsx file. Then the controller will call "ReadExcelService.ColH(file)" functions from factory. but when return the data to "$scope.colHeaders" in array. I saw "undefined". could you help me what problem? <script> var app=angular.module('myApp', []); app.factory('ReadExcelService',function(){ return{ ColH:function(f){ var cols=[]; var reader=new FileReader(); reader.onload=function(e){ var data = e.target.result; var workbook=XLSX.read(data, {type: 'binary'}); workbook.SheetNames.forEach(function(sheetName){ var headerNames=XLSX.utils.sheet_to_json(workbook.Sheets[sheetName],{header:1})[0]; headerNames.forEach(function(f){ cols.push(f); }); var dataSheet=XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]); }) return cols; }; reader.onerror=function(ex){console.log(ex);}; reader.readAsBinaryString(f); } //End CoH function }; }); //End ReadExcelService app.controller('myCtrl',['$scope','ReadExcelService',function($scope,ReadExcelService){ $scope.colHeaders=[]; $scope.readExcel=function(f){ var file = f.files[0]; switch(file.type){ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : $scope.$apply(function(){ $scope.colHeaders=ReadExcelService.ColH(file); }); //End $apply break default : alert("Unsupported Format"); break } }; }]); //End Controller </script>
The text was updated successfully, but these errors were encountered:
Hello all,
i coded controller in angularjs to to call "$scope.readExcel" after upload xlsx file. Then the controller will call "ReadExcelService.ColH(file)" functions from factory. but when return the data to "$scope.colHeaders" in array. I saw "undefined". could you help me what problem?
<script> var app=angular.module('myApp', []); app.factory('ReadExcelService',function(){ return{ ColH:function(f){ var cols=[]; var reader=new FileReader(); reader.onload=function(e){ var data = e.target.result; var workbook=XLSX.read(data, {type: 'binary'}); workbook.SheetNames.forEach(function(sheetName){ var headerNames=XLSX.utils.sheet_to_json(workbook.Sheets[sheetName],{header:1})[0]; headerNames.forEach(function(f){ cols.push(f); }); var dataSheet=XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]); }) return cols; }; reader.onerror=function(ex){console.log(ex);}; reader.readAsBinaryString(f); } //End CoH function }; }); //End ReadExcelService app.controller('myCtrl',['$scope','ReadExcelService',function($scope,ReadExcelService){ $scope.colHeaders=[]; $scope.readExcel=function(f){ var file = f.files[0]; switch(file.type){ case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" : $scope.$apply(function(){ $scope.colHeaders=ReadExcelService.ColH(file); }); //End $apply break default : alert("Unsupported Format"); break } }; }]); //End Controller </script>
The text was updated successfully, but these errors were encountered: