-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
50 lines (45 loc) · 1.27 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>生成excel</title>
</head>
<body>
<input type="button" value="生成表" />
<script type="text/javascript" src="./utils/shim.min.js"></script>
<script type="text/javascript" src="./utils/xlsx.full.min.js"></script>
<script type="text/javascript">
window.onload = (event) => {
main()
}
function main() {
const button = document.querySelector("input[type=button]")
button.onclick = (event) => {
const data = [];
creatTable(data)
}
}
function saveArrayDataToExcel(data) {
// create a new blank workbook
const workbook = XLSX.utils.book_new()
const worksheetName = "SheetJS"
const worksheetData = [
['title', 'name', 'tagName']
];
data.forEach((item) => {
worksheetData.push(item)
})
const worksheet = XLSX.utils.aoa_to_sheet(worksheetData)
XLSX.utils.book_append_sheet(workbook, worksheet, worksheetName)
XLSX.writeFile(workbook, `点位表${new Date().getTime()}.xlsx`)
}
function creatTable(data, title = 'tabTitle', name = 'descr', tagName = 'tagName') {
const list = [];
data.forEach((item) => {
list.push([item[title], item[name], item[tagName]]);
})
saveArrayDataToExcel(list);
}
</script>
</body>
</html>