index-xbf.html 6.3 KB
<!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>