The front end reads the excel file without the background

The front end of the header reads the excel file without the background

jsp code:

<script src="js/xlsx.full.min.js"></script>
	     	<div>
		     	<input  type="file" id="importExcel" name="importExcel" style="width:200px;display: inline-block;" value="导入明细"/>
		    </div>
		    <div style="margin-top: 10px;">
		        	<button class="btn btn-info" ng-click="uploadTrucksBut()">导入车辆文件</button>
		    </div>

js code:

	var importExcel = document.getElementById('importExcel');
	var file = null;
	if(importExcel.addEventListener) 
		importExcel.addEventListener('change', handleFile, false);
	function handleFile (e) {
		var files = e.target.files;
		file = files[0];
		
	};	
	function uploadTrucksBut (){
		 var name = file.name;
	    var reader = new FileReader();
		alert(1);
	    reader.readAsArrayBuffer(file);

        
	    reader.onload = function (e) {
	    	
	        var data = e.target.result;
	        var wb;
	        wb = XLSX.read(btoa(fixdata(data)), {//手动转化
                type: 'base64'
            });
	        var persons = []; // 存储获取到的数据
	        var truckInfos = new Array() ;
	        persons = persons.concat(XLSX.utils.sheet_to_json(wb.Sheets["Sheet1"]));
			alert(1);
	        angular.forEach(persons,function(data,idx){
	      
	        });
 
	    };
	    
	};

This method uses readAsArrayBuffer () compatible with ie11, see FileReader.readAsArrayBuffer () for
details .

Previously using readAsBinaryString This method has been abandoned by W3C and FileAPI. Not available in ie browser.

Published 137 original articles · Like 123 · Visit 250,000+

Guess you like

Origin blog.csdn.net/lz20120808/article/details/89186069