# js-excel
**Repository Path**: devin-alan/js-excel
## Basic Information
- **Project Name**: js-excel
- **Description**: js读取excel使用
- **Primary Language**: JavaScript
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 1
- **Created**: 2016-06-21
- **Last Updated**: 2022-05-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
本项目主要是一个使用SheetJS来读取excel的示例,详细项了解SheetJS请访问http://sheetjs.com。
本例有对xlxs.js文件中的sheet_to_json(sheet, opts)方法做了改动,改动的目的是为了能够根据需求指定从excel表的那一行开始读取数据。
SheetJs如果用来读取.xlsx的excel文件是必须使用jszip.js的。
除此之外,还对SheetJs读取excel做了一个简易的封装,可查看excelUtil.js。为了方便打包也整合了glup 。
glup构建:
```
npm install --save-dev
gulp min
```
usage:
```
//excel表数据检测
var ep = new ExcelUtil();
$("#uplBtn").on('click', function () {
$('#loadingCover', window.top.document).show();
ep.read({
"targetId": "xlf",
"label": "Open an Excel file"
}, process_wb);
});
//自定义处理过程
function process_wb(wb) {
var arr = [];//error data
//转成json
var output = ep.to_json(wb, 1);
for (var key in output) {
var list = output[key];
for (var i = 0; i < list.length; i++) {
var data = list[i];
if ($.yddkt.isEmpty(data['name'])) {
arr.push(data);
}
}
}
if (arr.length > 0) {
$('#loadingCover', window.top.document).hide();
var str = '姓名
';
for (var i = 0; i < arr.length; i++) {
str += arr[i]['name'] || '' + '
';
}
$.MsgBox.Alert("以下教室名称存在问题", str);
} else {
var formData = new FormData($("#uploadForm")[0]);
$.ajax({
url: 'xxx/import',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (result) {
$('#loadingCover', window.top.document).hide();
var data = result.data;
if (result.success) {
$grid.grid('reload');
var str = "姓名
";
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
str += data[i].name + '
';
}
$.MsgBox.Alert("以下教室信息已再系统中,不能再导入", str);
} else {
$("#lead_Box").hide();
window.top.frames.Alert("导入成功");
}
} else {
$.MsgBox.Alert("提示", data.message);
}
},
error: function () {
$.MsgBox.Alert("提示", "导入教室信息系统错误!");
}
});
}
}
```