1. 前台代码
1 <!DOCTYPE html> 2 <html lang="en" xmlns:th="http://www.thymeleaf.org"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>导入excel测试</title> 6 <style> 7 #fatherDiv{ 8 width:100px; 9 height:20px; 10 border:1px solid green; 11 } 12 #sonDiv{ 13 width:0px; 14 height:20px; 15 background:green; 16 } 17 </style> 18 19 <script th:src="@{|/js/jquery-2.1.4.min.js/|}"></script> 20 <script> 21 $(function () { 22 23 $("#importExcel").bind("click", function () { 24 25 /* 判断是否有导入文件 */ 26 if (!$("#excel").val()) { 27 window.alert("请导入excel文件"); 28 return; 29 } 30 31 /* 判断输入的文件的类型 */ 32 var splitArray = $("#excel").val().toLowerCase().split("."); 33 var type = splitArray[splitArray.length - 1]; 34 if (type != "xls" && type != "xlsx") { 35 window.alert("导入的文件类型有误"); 36 return; 37 } 38 39 // 获取excel对象 40 var excel = $("#excel")[0].files[0]; 41 42 /* 判断输入的excel文件的大小 */ 43 var excelSize = excel.size; 44 if (excelSize > 1024 * 1024 * 10) { 45 window.alert("当前上传的excel文件的大小为" + 46 Math.round(excelSize / 1024 / 1024 * 100) / 100 + 47 "M,超过10M"); 48 return; 49 } 50 51 var formData =