Angular can't pass value from read xlsx file #447
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#447
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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>
@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