纯JS实现的读取excel文件内容功能示例【支持所有浏览器】

前端之家收集整理的这篇文章主要介绍了纯JS实现的读取excel文件内容功能示例【支持所有浏览器】前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了纯JS实现的读取excel文件内容功能分享给大家供大家参考,具体如下:

template.html

<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> JS-XLSX Live Demo nofollow" rel="stylesheet">
返回
Box" name="useworker" checked="" style="display: none;">
Box" name="xferable" checked="" style="display: none;">
Box" name="userabs" checked="" style="display: none;">

myexcel.js

dio_value( radioName ) { var radios = document.getElementsByName( radioName ); for( var i = 0; i < radios.length; i++ ) { if( radios[i].checked || radios.length === 1 ) { return radios[i].value; } } } function to_json(workbook) { var result = {}; workbook.SheetNames.forEach(function(sheetName) { var roa = X.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]); if(roa.length > 0){ result[sheetName] = roa; } }); return result; } var tarea = document.getElementById('b64data'); function b64it() { if(typeof console !== 'undefined') console.log("onload",new Date()); var wb = X.read(tarea.value,{type: 'base64',WTF:wtf_mode}); process_wb(wb); } var token=Cookies.get("token"); console.log(token); if(token==null){ // alert("你是怎么进来的?请先登录"); // window.location.href="../login.html" rel="external nofollow" ; } var global_wb; function process_wb(wb) { global_wb = wb; var output = ""; //这里是成绩批量录入代码,可以忽略不计 $(".submit_all").on("click",function(){ var array=Object.values(to_json(wb))[0]; var len=array.length; var array1="",array2="",array3="",array4="",array5=""; for(var i=0;inofollow" rel="external nofollow" ; } else if(res.state==1){ alert("您输入的学号不存在"); } }); }) output = JSON.stringify(to_json(wb),2,2); if(out.innerText === undefined) out.textContent = output; else out.innerText = output; if(typeof console !== 'undefined') console.log(output); } function setfmt() {if(global_wb) process_wb(global_wb);} var xlf = document.getElementById('xlf'); function handleFile(e) { rABS = document.getElementsByName("userabs")[0].checked; use_worker = document.getElementsByName("useworker")[0].checked; var files = e.target.files; var f = files[0]; { var reader = new FileReader(); var name = f.name; reader.onload = function(e) { if(typeof console !== 'undefined') var data = e.target.result; if(use_worker) { xw(data,process_wb); } else { var wb; if(rABS) { wb = X.read(data,{type: 'binary'}); } else { var arr = fixdata(data); wb = X.read(btoa(arr),{type: 'base64'}); } process_wb(wb); } }; if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); } } if(xlf.addEventListener) xlf.addEventListener('change',handleFile,false);

导入一个新建的excel

查看读取到的值,以json格式显示

给大家一个GitHub插件包下载地址: https://github.com/SheetJS/js-xlsx

更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》及《

希望本文所述对大家JavaScript程序设计有所帮助。

原文链接:https://www.f2er.com/js/31816.html

猜你在找的JavaScript相关文章