index-xbf.html
6.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>x-spreadsheet</title>
<link href="xspreadsheet.css" rel="stylesheet"></head>
<body onload="load()">
<input type="button" name="test" onclick="submitData()" value="确定"></input>
<div id="x-spreadsheet-demo"></div>
<h1>效果如下</h1>
<table id="test" border="1" style="margin: 0 30px;border-collapse: collapse;"></table>
<br>
<br>
<script>
var result;
function submitData(){
//将json数据提交到后端
result.rows[2].type="list";
//添加合并单元格
result.rows[2].cells[0].listMergeTag="yes";
//为列表添加属性
var str = JSON.stringify(result);
console.log(str);
//alert("模板解析事件");
$.ajax({
type : "POST",
url : "/skboot/sys/sysExcelParse/parse",
contentType:"application/json",
data : str,
dataType : "json",
success : function(msg) {
$("#test").html(msg.result);
}
});
}
function load(){
// x.spreadsheet.locale('zh-cn');
var xs = x.spreadsheet('#x-spreadsheet-demo', {showToolbar: true, showGrid: true})
.loadData({
"autofilter": {},
"cols": {
"1": {
"width": 160
},
"2": {
"width": 174
},
"3": {
"width": 199
},
"len": 26
},
"freeze": "A1",
"merges": [
"A1:D1"
],
"name": "sheet1",
"rows": {
"0": {
"cells": {
"0": {
"merge": [
0,
3
],
"style": 3,
"text": "小泵房流量统计表"
},
"1": {
"style": 4
},
"2": {
"style": 4
},
"3": {
"style": 4
}
},
"height": 46
},
"1": {
"cells": {
"0": {
"style": 1,
"text": "日期"
},
"1": {
"style": 1,
"text": "累计流量"
},
"2": {
"style": 1,
"text": "当日流量"
},
"3": {
"style": 1,
"text": "备注"
}
}
},
"2": {
"cells": {
"0": {
"style": 1,
"text": "{ds.A}"
},
"1": {
"style": 1,
"text": "{ds.B}"
},
"2": {
"style": 1,
"text": "{ds.C}"
},
"3": {
"style": 1,
"text": "{ds.D}"
}
}
},
"len": 100
},
"styles": [
{
"align": "center"
},
{
"align": "center",
"border": {
"bottom": [
"thin",
"#000"
],
"left": [
"thin",
"#000"
],
"right": [
"thin",
"#000"
],
"top": [
"thin",
"#000"
]
}
},
{
"border": {
"bottom": [
"thin",
"#000"
],
"left": [
"thin",
"#000"
],
"right": [
"thin",
"#000"
],
"top": [
"thin",
"#000"
]
}
},
{
"align": "center",
"border": {
"bottom": [
"thin",
"#000"
],
"left": [
"thin",
"#000"
],
"right": [
"thin",
"#000"
],
"top": [
"thin",
"#000"
]
},
"font": {
"size": 16
}
},
{
"align": "center",
"font": {
"size": 16
}
}
],
"validations": []
}).change((cdata) => {
console.log(cdata);
console.log(xs.validate());
result=cdata;
});
}
</script>
<!--script type="text/javascript" src="https://unpkg.com/x-data-spreadsheet@1.0.20/dist/locale/zh-cn.js"></script-->
<script type="text/javascript" src="xspreadsheet.js"></script>
<script type="text/javascript" src="../generic/build/jquery-2.1.1.js"></script>
</body>
</html>