Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular can't pass value from read xlsx file #447

Closed
channara opened this issue Jul 27, 2016 · 1 comment
Closed

Angular can't pass value from read xlsx file #447

channara opened this issue Jul 27, 2016 · 1 comment

Comments

@channara
Copy link

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>

@SheetJSDev
Copy link
Contributor

@channara we are adding an angular demo based on https://github.com/brexis/angular-js-xlsx -- please test and let us know if there are any issues

saarCiklum pushed a commit to Folcon/js-xlsx that referenced this issue Aug 19, 2020
closes SheetJS#447 h/t @channara
closes SheetJS#453 h/t @Adtiv @paustint
closes SheetJS#538 h/t @hsbilgen
closes SheetJS#547 h/t @Mani2693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants