可以用
https://github.com/SheetJS/js-xlsx/blob/master/dist/xlsx.core.min.js
这个
html
<input type="file" id="" onchange="duxlsx(this)" id="" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
js
function duxlsx(obj) {
if(!obj.files) {
return;
}
var f = obj.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result;
var wb = XLSX.read(data, {
type: 'binary' //binary二进制
});
var worksheet = wb.Sheets[wb.SheetNames[0]];
var result = tocvs(worksheet);
};
reader.readAsBinaryString(f);
}
//把xlsx内容变成,分割
var tocvs = function(sheet) {
var result = [];
var row;
var rowNum;
var colNum;
var range = XLSX.utils.decode_range(sheet['!ref']);
for(rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
row = [];
for(colNum = range.s.c; colNum <= range.e.c; colNum++) {
var nextCell = sheet[
XLSX.utils.encodecell({
r: rowNum,
c: colNum
})
];
if(typeof nextCell === 'undefined') {
row.push(void 0);
} else row.push(nextCell.w);
}
result.push(row);
}
return result;
};
可能已经晚了,但是以后会有人用到的→→
2 个回复
atongmu - 个人承接python、uniapp项目。联系QQ 2406176321
我也遇到这个问题了,这个问题都石沉大海了,唉~~!
2***@qq.com - 前端小白
可以用
https://github.com/SheetJS/js-xlsx/blob/master/dist/xlsx.core.min.js
这个
html
<input type="file" id="" onchange="duxlsx(this)" id="" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
js
function duxlsx(obj) {
}
//把xlsx内容变成,分割
var tocvs = function(sheet) {
var result = [];
var row;
var rowNum;
var colNum;
var range = XLSX.utils.decode_range(sheet['!ref']);
for(rowNum = range.s.r; rowNum <= range.e.r; rowNum++) {
row = [];
for(colNum = range.s.c; colNum <= range.e.c; colNum++) {
var nextCell = sheet[
XLSX.utils.encodecell({
r: rowNum,
c: colNum
})
];
if(typeof nextCell === 'undefined') {
row.push(void 0);
} else row.push(nextCell.w);
}
result.push(row);
}
return result;
};
可能已经晚了,但是以后会有人用到的→→