<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Excel批量处理</title>
<script type="text/javascript" src="xlxscore.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/xlsx/0.11.5/xlsx.core.min.js"></script>
</head>
<body>
<button id="daoru">导入exec表</button>
<!-- 让input隐藏 -->
<input type="file" id="daoruexcel" style="display: none;">
<script>
// 当点击导入表时触动input元素改变事件
$("#daoru").click(function(){
$("#daoruexcel").click();
});
//给input标签绑定change事件,一上传就触发函数
$('#daoruexcel').change(function(e) {
//获取文件
var files = e.target.files;
var fileReader = new FileReader();
//加载文件
fileReader.onload = function(ev) {
try {
//获取文件中的数据
var data = ev.target.result
var workbook = XLSX.read(data, {
type: 'binary'
})
var persons = [];
} catch (e) {
console.log(e);
console.log('文件类型不正确');
return;
}
// var fromTo = '';
for (var sheet in workbook.Sheets) {
if (workbook.Sheets.hasOwnProperty(sheet)) {
// fromTo = workbook.Sheets[sheet]['!ref'];
persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
}
}
//在控制台打印出来表格中的数据
console.log(persons);
};
fileReader.readAsBinaryString(files[0]);
});
</script>
</body>
</html>
前端js使用exec导入到控制台
最新推荐文章于 2024-11-07 10:38:40 发布