将 Excel中数据按某一个字段归类成一个josn插件
- 需要将Exce数据按想要归类的字段排序,使用echart工具转为json格式。
- 支持合并(想要归类的字段)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="reset.min.css" />
</head>
<style type="text/css">
#Tit {
width: 1000px;
margin: 50px auto;
text-align: justify;
border: 1px salmon solid;
color: #333;
font-size: 12px;
min-height: 50px;
max-height: 800px;
overflow-y: scroll;
padding: 20px;
}
</style>
<body>
输入转换:
<input type="text" id="input">
输入字段:
<input type="text" id="keyword">
<button id="produce">launch</button>
<div id="Tit">
</div>
<script>
function bol(obj, str) {
var preObj = obj[0]
var All = []
var arr = []
for (v of obj) {
if ((v[str] == preObj[str]) || (v[str] == "-") || !v[str]) {
arr.push(v)
} else {
if (arr.length) {
All.push(arr.slice())
arr = []
}
arr.push(v)
preObj = v
}
}
All.push(arr.slice())
console.log(All)
var objs = {}
for (v of All) {
objs[v[0][str]] = v
}
Tit.innerText = JSON.stringify(objs)
}
produce.onclick = function() {
bol(JSON.parse(input.value), keyword.value)
}
</script>
</body>
</html>