當(dāng)前位置:
首頁 >
js读取excel
發(fā)布時間:2023/12/31
41
豆豆
技術(shù)交流QQ群 933925017
1.下載 excel庫
- 地址 https://github.com/SheetJS/js-xlsx
2.編寫代碼 引入jq 和excel-core
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><script src="js/xlsx.core.min.js"></script><script src="js/jquery.min.js"></script> </head> <body> <input id="file" type="file"> <p><button>寫入所號</button> </p> <script>var list = [];// 讀取本地excel文件function readWorkbookFromLocalFile(file, callback) {var reader = new FileReader();reader.onload = function(e) {var data = e.target.result;var wb = XLSX.read(data, {type: 'binary'});var text = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]);if(callback) callback(text);};reader.readAsBinaryString(file);}$("#file").change(function () {if(!this.files) {return;}var f = this.files[0];readWorkbookFromLocalFile(f,function (value) {list = value;})})$('button').click(function () {// 發(fā)送網(wǎng)絡(luò)請求var s = '';for (const x of list) {// console.log(x)s = s + 'list_num[]=' + x.num + "&";}s = s.substring(0,s.length-1);console.log(s);var url = `http://localhost/guicheng/public/api/import_white?${s}`;$.get(url,{},function (res) {console.log(res)},'json')}) </script> </body> </html>總結(jié)
- 上一篇: Hbase 详细介绍以及简单的Hbase
- 下一篇: svn往分支提代码_SVN建立分支和合并